@@ -66,7 +66,7 @@ func DecryptECB(cipherText []byte, key []byte, padding int) ([]byte, error) {
6666// The length of the <key> should be either 16 or 24 bytes.
6767func EncryptECBTriple (plainText []byte , key []byte , padding int ) ([]byte , error ) {
6868 if len (key ) != 16 && len (key ) != 24 {
69- return nil , gerror .New ( "key length error" )
69+ return nil , gerror .NewCode ( gerror . CodeInvalidParameter , "key length error" )
7070 }
7171
7272 text , err := Padding (plainText , padding )
@@ -100,7 +100,7 @@ func EncryptECBTriple(plainText []byte, key []byte, padding int) ([]byte, error)
100100// The length of the <key> should be either 16 or 24 bytes.
101101func DecryptECBTriple (cipherText []byte , key []byte , padding int ) ([]byte , error ) {
102102 if len (key ) != 16 && len (key ) != 24 {
103- return nil , gerror .New ( "key length error" )
103+ return nil , gerror .NewCode ( gerror . CodeInvalidParameter , "key length error" )
104104 }
105105
106106 var newKey []byte
@@ -138,7 +138,7 @@ func EncryptCBC(plainText []byte, key []byte, iv []byte, padding int) ([]byte, e
138138 }
139139
140140 if len (iv ) != block .BlockSize () {
141- return nil , gerror .New ( "iv length invalid" )
141+ return nil , gerror .NewCode ( gerror . CodeInvalidParameter , "iv length invalid" )
142142 }
143143
144144 text , err := Padding (plainText , padding )
@@ -161,7 +161,7 @@ func DecryptCBC(cipherText []byte, key []byte, iv []byte, padding int) ([]byte,
161161 }
162162
163163 if len (iv ) != block .BlockSize () {
164- return nil , gerror .New ( "iv length invalid" )
164+ return nil , gerror .NewCode ( gerror . CodeInvalidParameter , "iv length invalid" )
165165 }
166166
167167 text := make ([]byte , len (cipherText ))
@@ -179,7 +179,7 @@ func DecryptCBC(cipherText []byte, key []byte, iv []byte, padding int) ([]byte,
179179// EncryptCBCTriple encrypts <plainText> using TripleDES and CBC mode.
180180func EncryptCBCTriple (plainText []byte , key []byte , iv []byte , padding int ) ([]byte , error ) {
181181 if len (key ) != 16 && len (key ) != 24 {
182- return nil , gerror .New ( "key length invalid" )
182+ return nil , gerror .NewCode ( gerror . CodeInvalidParameter , "key length invalid" )
183183 }
184184
185185 var newKey []byte
@@ -196,7 +196,7 @@ func EncryptCBCTriple(plainText []byte, key []byte, iv []byte, padding int) ([]b
196196 }
197197
198198 if len (iv ) != block .BlockSize () {
199- return nil , gerror .New ( "iv length invalid" )
199+ return nil , gerror .NewCode ( gerror . CodeInvalidParameter , "iv length invalid" )
200200 }
201201
202202 text , err := Padding (plainText , padding )
@@ -214,7 +214,7 @@ func EncryptCBCTriple(plainText []byte, key []byte, iv []byte, padding int) ([]b
214214// DecryptCBCTriple decrypts <cipherText> using TripleDES and CBC mode.
215215func DecryptCBCTriple (cipherText []byte , key []byte , iv []byte , padding int ) ([]byte , error ) {
216216 if len (key ) != 16 && len (key ) != 24 {
217- return nil , gerror .New ( "key length invalid" )
217+ return nil , gerror .NewCode ( gerror . CodeInvalidParameter , "key length invalid" )
218218 }
219219
220220 var newKey []byte
@@ -231,7 +231,7 @@ func DecryptCBCTriple(cipherText []byte, key []byte, iv []byte, padding int) ([]
231231 }
232232
233233 if len (iv ) != block .BlockSize () {
234- return nil , gerror .New ( "iv length invalid" )
234+ return nil , gerror .NewCode ( gerror . CodeInvalidParameter , "iv length invalid" )
235235 }
236236
237237 text := make ([]byte , len (cipherText ))
@@ -262,12 +262,12 @@ func Padding(text []byte, padding int) ([]byte, error) {
262262 switch padding {
263263 case NOPADDING :
264264 if len (text )% 8 != 0 {
265- return nil , gerror .New ( "text length invalid" )
265+ return nil , gerror .NewCode ( gerror . CodeInvalidParameter , "text length invalid" )
266266 }
267267 case PKCS5PADDING :
268268 return PaddingPKCS5 (text , 8 ), nil
269269 default :
270- return nil , gerror .New ( "padding type error" )
270+ return nil , gerror .NewCode ( gerror . CodeInvalidParameter , "padding type error" )
271271 }
272272
273273 return text , nil
@@ -277,12 +277,12 @@ func UnPadding(text []byte, padding int) ([]byte, error) {
277277 switch padding {
278278 case NOPADDING :
279279 if len (text )% 8 != 0 {
280- return nil , gerror .New ( "text length invalid" )
280+ return nil , gerror .NewCode ( gerror . CodeInvalidParameter , "text length invalid" )
281281 }
282282 case PKCS5PADDING :
283283 return UnPaddingPKCS5 (text ), nil
284284 default :
285- return nil , gerror .New ( "padding type error" )
285+ return nil , gerror .NewCode ( gerror . CodeInvalidParameter , "padding type error" )
286286 }
287287 return text , nil
288288}
0 commit comments