ag_tools/types/rsa.go

44 lines
654 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
}
}