Created
September 15, 2023 09:06
-
-
Save kleewho/ddee71eee8c1c09835a13ed126db8bce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func NewLegacyCryptoModule(cipherKey string, randomIv bool) (CryptorModule, error) { | |
legacyCryptoAlgorithm, e := NewLegacyCryptoAlgorithm(cipherKey, randomIv) | |
if e != nil { | |
return nil, e | |
} | |
aesCBCCryptoAlgorithm, e := NewAesCBCCryptoAlgorithm(cipherKey) | |
if e != nil { | |
return nil, e | |
} | |
decryptors := []CryptoAlgorithm{aesCBCCryptoAlgorithm} | |
return NewCryptoModule(legacyCryptoAlgorithm, decryptors), nil | |
} | |
func NewDefaultCryptoModule(cipherKey string, randomIv bool) (CryptorModule, error) { | |
aesCBCCryptoAlgorithm, e := NewAesCBCCryptoAlgorithm(cipherKey) | |
if e != nil { | |
return nil, e | |
} | |
legacyCryptoAlgorithm, e := NewLegacyCryptoAlgorithm(cipherKey, randomIv) | |
if e != nil { | |
return nil, e | |
} | |
decryptors := []CryptoAlgorithm{legacyCryptoAlgorithm} | |
return NewCryptoModule(aesCBCCryptoAlgorithm, decryptors), nil | |
} | |
func NewCryptoModule(defaultCryptoAlgorithm CryptoAlgorithm, decryptingAlgorithms []CryptoAlgorithm) CryptorModule { | |
decryptors := make(map[string]cryptorWrapper, len(decryptingAlgorithms)+1) | |
for _, decryptor := range decryptingAlgorithms { | |
decryptors[decryptor.Id()] = NewCryptor(decryptor) | |
} | |
encryptor := NewCryptor(defaultCryptoAlgorithm) | |
decryptors[defaultCryptoAlgorithm.Id()] = encryptor | |
return &Module{ | |
encryptor: encryptor, | |
decryptors: decryptors, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment