mirror of
https://github.com/go-i2p/go-i2p.git
synced 2025-07-05 06:05:16 -04:00
testing and improvements to the common data structures
This commit is contained in:
46
lib/common/key_certificate.go
Normal file
46
lib/common/key_certificate.go
Normal file
@ -0,0 +1,46 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"github.com/bounce-chat/go-i2p/lib/crypto"
|
||||
)
|
||||
|
||||
type KeyCertificate []byte
|
||||
|
||||
func (key_certificate KeyCertificate) Type() byte {
|
||||
return Certificate(key_certificate).Type()
|
||||
}
|
||||
|
||||
func (key_certificate KeyCertificate) Data() ([]byte, error) {
|
||||
return Certificate(key_certificate).Data()
|
||||
}
|
||||
|
||||
// get the signing public key from this key cert
|
||||
func (key_certificate KeyCertificate) SigningPublicKey() (k crypto.SigningPublicKey) {
|
||||
data, err := key_certificate.Data()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
ktype := Integer(data[:2])
|
||||
// set data to be the key data now
|
||||
data = data[4:]
|
||||
// determine the key type
|
||||
if ktype == KEYCERT_SIGN_DSA_SHA1 {
|
||||
var pk crypto.DSAPublicKey
|
||||
copy(pk[:], data[:pk.Len()])
|
||||
k = pk
|
||||
} else if ktype == KEYCERT_SIGN_P256 {
|
||||
var pk crypto.ECP256PublicKey
|
||||
copy(pk[:], data[:pk.Len()])
|
||||
k = pk
|
||||
} else if ktype == KEYCERT_SIGN_P384 {
|
||||
var pk crypto.ECP384PublicKey
|
||||
copy(pk[:], data[:pk.Len()])
|
||||
k = pk
|
||||
} else if ktype == KEYCERT_SIGN_P521 {
|
||||
var pk crypto.ECP521PublicKey
|
||||
copy(pk[:], data[:pk.Len()])
|
||||
k = pk
|
||||
}
|
||||
// TODO: rsa/eddsa
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user