/
metadata.go
50 lines (40 loc) · 820 Bytes
/
metadata.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package rsa
type PrivateKeyInfo struct {
BitLen int
Size int
Error string
}
type PublicKeyInfo struct {
BitLen int
Size int
E int
}
func (r *FastRSA) MetadataPrivateKey(privateKey string) (*PrivateKeyInfo, error) {
private, err := r.readPrivateKey(privateKey)
if err != nil {
return nil, err
}
validate := ""
err = private.Validate()
if err != nil {
validate = err.Error()
}
info := &PrivateKeyInfo{
BitLen: private.D.BitLen(),
Size: private.Size(),
Error: validate,
}
return info, nil
}
func (r *FastRSA) MetadataPublicKey(publicKey string) (*PublicKeyInfo, error) {
public, err := r.readPublicKey(publicKey)
if err != nil {
return nil, err
}
info := &PublicKeyInfo{
BitLen: public.N.BitLen(),
Size: public.Size(),
E: public.E,
}
return info, nil
}