26 lines
516 B
Go
26 lines
516 B
Go
|
|
package symm
|
||
|
|
|
||
|
|
// CipherOptions provides a unified configuration for symmetric APIs.
|
||
|
|
// For GCM mode, Nonce is used; if Nonce is empty, IV is used as fallback.
|
||
|
|
type CipherOptions struct {
|
||
|
|
Mode string
|
||
|
|
Padding string
|
||
|
|
IV []byte
|
||
|
|
Nonce []byte
|
||
|
|
AAD []byte
|
||
|
|
}
|
||
|
|
|
||
|
|
func normalizeCipherOptions(opts *CipherOptions) CipherOptions {
|
||
|
|
if opts == nil {
|
||
|
|
return CipherOptions{}
|
||
|
|
}
|
||
|
|
return *opts
|
||
|
|
}
|
||
|
|
|
||
|
|
func nonceFromOptions(opts CipherOptions) []byte {
|
||
|
|
if len(opts.Nonce) > 0 {
|
||
|
|
return opts.Nonce
|
||
|
|
}
|
||
|
|
return opts.IV
|
||
|
|
}
|