44 lines
654 B
Go
44 lines
654 B
Go
package types
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"archgrid.xyz/ag/toolsbox/encryption/rsa"
|
|
)
|
|
|
|
type RSAKeyBits string
|
|
|
|
const (
|
|
RSA1024 RSAKeyBits = "1024"
|
|
RSA2048 RSAKeyBits = "2048"
|
|
)
|
|
|
|
func (r *RSAKeyBits) String() string {
|
|
return string(*r)
|
|
}
|
|
|
|
func (r *RSAKeyBits) Set(s string) error {
|
|
switch s {
|
|
case "1024", "2048":
|
|
*r = RSAKeyBits(s)
|
|
return nil
|
|
default:
|
|
return fmt.Errorf("不支持的RSA密钥长度:%s", s)
|
|
}
|
|
}
|
|
|
|
func (r *RSAKeyBits) Type() string {
|
|
return "RSAKeyBits"
|
|
}
|
|
|
|
func (r RSAKeyBits) IntoRSAKeyLength() rsa.KeyLength {
|
|
switch r {
|
|
case RSA1024:
|
|
return rsa.RSA1024
|
|
case RSA2048:
|
|
return rsa.RSA2048
|
|
default:
|
|
return rsa.RSA2048
|
|
}
|
|
}
|