@@ -28,7 +28,7 @@ func main() {
28
28
29
29
if * apikey != "" {
30
30
if * hmacSalt == "auto" {
31
- fmt . Printf ( " Cannot validate the key with 'auto' HMAC salt" )
31
+ log . Printn ( "Error: Cannot validate the key with 'auto' HMAC salt" )
32
32
os .Exit (1 )
33
33
}
34
34
os .Exit (validate (* apikey , * hmacSalt ))
@@ -61,7 +61,7 @@ func generate(sequence, isRoot int, hmacSaltB64 string) int {
61
61
hmacSalt = make ([]byte , 32 )
62
62
_ , err := rand .Read (hmacSalt )
63
63
if err != nil {
64
- log .Println ("Failed to generate HMAC salt" , err )
64
+ log .Println ("Error: Failed to generate HMAC salt" , err )
65
65
return 1
66
66
}
67
67
} else {
@@ -72,7 +72,7 @@ func generate(sequence, isRoot int, hmacSaltB64 string) int {
72
72
hmacSalt , err = base64 .StdEncoding .DecodeString (hmacSaltB64 )
73
73
}
74
74
if err != nil {
75
- log .Println ("Failed to decode HMAC salt" , err )
75
+ log .Println ("Error: Failed to decode HMAC salt" , err )
76
76
return 1
77
77
}
78
78
}
@@ -119,26 +119,26 @@ func validate(apikey string, hmacSaltB64 string) int {
119
119
hmacSalt , err = base64 .StdEncoding .DecodeString (hmacSaltB64 )
120
120
}
121
121
if err != nil {
122
- log .Println ("Failed to decode HMAC salt" , err )
122
+ log .Println ("Error: Failed to decode HMAC salt" , err )
123
123
return 1
124
124
}
125
125
126
126
if declen := base64 .URLEncoding .DecodedLen (len (apikey )); declen != APIKEY_LENGTH {
127
- log .Printf ("Invalid key length %d, expecting %d" , declen , APIKEY_LENGTH )
127
+ log .Printf ("Error: Invalid key length %d, expecting %d" , declen , APIKEY_LENGTH )
128
128
return 1
129
129
}
130
130
131
131
data , err := base64 .URLEncoding .DecodeString (apikey )
132
132
if err != nil {
133
- log .Println ("Failed to decode key as base64-URL-encoded" , err )
133
+ log .Println ("Error: Failed to decode key as base64-URL-encoded" , err )
134
134
return 1
135
135
}
136
136
137
137
buf := bytes .NewReader (data )
138
138
binary .Read (buf , binary .LittleEndian , & version )
139
139
140
140
if version != 1 {
141
- log .Println ("Unknown signature algorithm " , data [ 0 ] )
141
+ log .Println ("Error: Unknown signature algorithm " , version )
142
142
return 1
143
143
}
144
144
@@ -147,7 +147,7 @@ func validate(apikey string, hmacSaltB64 string) int {
147
147
signature := hasher .Sum (nil )
148
148
149
149
if ! bytes .Equal (data [APIKEY_VERSION + APIKEY_APPID + APIKEY_SEQUENCE + APIKEY_WHO :], signature ) {
150
- fmt .Println ("Invalid signature " , data , signature )
150
+ log .Println ("Error: Invalid signature " , data , signature )
151
151
return 1
152
152
}
153
153
// [1:algorithm version][4:deprecated][2:key sequence][1:isRoot]
0 commit comments