7 // Authenticates the supplied user with the supplied password. Blocks until we have a reply.
8 // Needed before almost any other API command can be used.
10 // If the udpKey is not "", then the connection will be encrypted, but the protocol's
11 // encryption uses the VERY weak ECB mode.
13 // http://wiki.anidb.net/w/UDP_API_Definition#AUTH:_Authing_to_the_AnimeDB
15 // http://wiki.anidb.net/w/UDP_API_Definition#ENCRYPT:_Start_Encrypted_Session
16 func (a *AniDBUDP) Auth(user, password, udpKey string) (reply APIReply) {
18 if reply = <-a.Uptime(); reply.Error() == nil {
25 if reply = a.encrypt(user, udpKey); reply.Error() != nil {
29 reply = <-a.SendRecv("AUTH", ParamMap{
33 "client": "goanidbudp",
41 f := strings.Fields(reply.Text())
47 // Ends the API session. Blocks until we have confirmation.
49 // http://wiki.anidb.net/w/UDP_API_Definition#LOGOUT:_Logout
50 func (a *AniDBUDP) Logout() (err error) {
51 r := <-a.SendRecv("LOGOUT", ParamMap{})
56 func (a *AniDBUDP) encrypt(user, udpKey string) (reply APIReply) {
58 if reply = <-a.SendRecv("ENCRYPT", ParamMap{"user": user, "type": 1}); reply.Error() == nil {
61 salt := []byte(strings.Fields(reply.Text())[0])
63 // Yes, AniDB works in ECB mode
64 a.ecb = newECBState(udpKey, salt)