-
-
Notifications
You must be signed in to change notification settings - Fork 118
/
key.go
46 lines (37 loc) · 936 Bytes
/
key.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
package exchange
import (
"crypto/rsa"
"github.com/gotd/td/internal/crypto"
)
// PublicKey is a public Telegram server key.
type PublicKey struct {
// RSA public key.
RSA *rsa.PublicKey
}
// Zero denotes that current PublicKey is zero value.
func (k PublicKey) Zero() bool {
return k.RSA == nil
}
// Fingerprint computes key fingerprint.
func (k PublicKey) Fingerprint() int64 {
return crypto.RSAFingerprint(k.RSA)
}
// PrivateKey is a private Telegram server key.
type PrivateKey struct {
// RSA private key.
RSA *rsa.PrivateKey
}
// Zero denotes that current PublicKey is zero value.
func (k PrivateKey) Zero() bool {
return k.RSA == nil
}
// Fingerprint computes key fingerprint.
func (k PrivateKey) Fingerprint() int64 {
return crypto.RSAFingerprint(&k.RSA.PublicKey)
}
// Public returns PublicKey of this PrivateKey pair.
func (k PrivateKey) Public() PublicKey {
return PublicKey{
RSA: &k.RSA.PublicKey,
}
}