go_pgp/CreateOptions.go
2024-05-10 22:24:14 +02:00

72 lines
1.3 KiB
Go

package go_pgp
import (
"crypto"
"github.com/ProtonMail/go-crypto/openpgp/packet"
)
const (
// The minimal number of RSA bits
MinRSABits = 3072
)
type createOption func(cfg *packet.Config)
func HashOption(h crypto.Hash) createOption {
if !h.Available() {
h = 0
}
return func(cfg *packet.Config) {
cfg.DefaultHash = h
}
}
func CipherOption(cipher packet.CipherFunction) createOption {
if !cipher.IsSupported() {
cipher = 0
}
return func(cfg *packet.Config) {
cfg.DefaultCipher = cipher
}
}
func RSABitsOption(numBits int) createOption {
if numBits < MinRSABits {
numBits = MinRSABits
}
return func(cfg *packet.Config) {
cfg.RSABits = numBits
}
}
type CompressionLevel int
const (
DefaultCompression CompressionLevel = iota - 1
NoCompression
CompressionLevel1
CompressionLevel2
CompressionLevel3
CompressionLevel4
CompressionLevel5
CompressionLevel6
CompressionLevel7
CompressionLevel8
CompressionLevel9
compressionLevelOutOfRange
)
const CompressionLevelMax = compressionLevelOutOfRange - 1
func CompressionOption(level CompressionLevel) createOption {
if level < DefaultCompression || level > CompressionLevelMax {
level = CompressionLevel5
}
return func(cfg *packet.Config) {
cfg.CompressionConfig = &packet.CompressionConfig{
Level: int(level),
}
}
}