Skip to content

Commit

Permalink
Switch with default error case in encryptAES*
Browse files Browse the repository at this point in the history
Per PR feedback from @jvehent
  • Loading branch information
eriksw committed Aug 23, 2018
1 parent 0c38e3d commit a91be25
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions encrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,15 @@ type aesGCMParameters struct {
func encryptAESGCM(content []byte, key []byte) ([]byte, *encryptedContentInfo, error) {
var keyLen int
var algID asn1.ObjectIdentifier
if ContentEncryptionAlgorithm == EncryptionAlgorithmAES128GCM {
switch ContentEncryptionAlgorithm {
case EncryptionAlgorithmAES128GCM:
keyLen = 16
algID = OIDEncryptionAlgorithmAES128GCM
} else {
case EncryptionAlgorithmAES256GCM:
keyLen = 32
algID = OIDEncryptionAlgorithmAES256GCM
default:
return nil, nil, fmt.Errorf("invalid ContentEncryptionAlgorithm in encryptAESGCM: %d", ContentEncryptionAlgorithm)
}
if key == nil {
// Create AES key
Expand Down Expand Up @@ -191,12 +194,15 @@ func encryptDESCBC(content []byte, key []byte) ([]byte, *encryptedContentInfo, e
func encryptAESCBC(content []byte, key []byte) ([]byte, *encryptedContentInfo, error) {
var keyLen int
var algID asn1.ObjectIdentifier
if ContentEncryptionAlgorithm == EncryptionAlgorithmAES128CBC {
switch ContentEncryptionAlgorithm {
case EncryptionAlgorithmAES128CBC:
keyLen = 16
algID = OIDEncryptionAlgorithmAES128CBC
} else {
case EncryptionAlgorithmAES256CBC:
keyLen = 32
algID = OIDEncryptionAlgorithmAES256CBC
default:
return nil, nil, fmt.Errorf("invalid ContentEncryptionAlgorithm in encryptAESCBC: %d", ContentEncryptionAlgorithm)
}

if key == nil {
Expand Down

0 comments on commit a91be25

Please sign in to comment.