Hello Gophers, I have wrote some encryption and decryption code recently and find out in cbcDecrypter , and cbcEncrypter provided by runtime, it panic instead of return error, thus I need to used defer to recover from the panic , if it ever happens
The question is why it is implement in this way? For example h ttps://github.com/golang/go/blob/master/src/crypto/cipher/cbc.go#L114 my guess is because interface is designed that way. https://github.com/golang/go/blob/master/src/crypto/cipher/cipher.go#L45 type BlockMode interface { // BlockSize returns the mode's block size. BlockSize() int // CryptBlocks encrypts or decrypts a number of blocks. The length of // src must be a multiple of the block size. Dst and src may point to // the same memory. CryptBlocks(dst, src []byte) } Is there a reason why the interface is not design in a way that returns error? what I means is like type BlockMode interface { // BlockSize returns the mode's block size. BlockSize() (int,error) // CryptBlocks encrypts or decrypts a number of blocks. The length of // src must be a multiple of the block size. Dst and src may point to // the same memory. CryptBlocks(dst, src []byte) error } Thanks -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.