mirror of
https://github.com/go-i2p/go-i2p.git
synced 2025-06-07 18:24:25 -04:00
testing and improvements to the common data structures
This commit is contained in:
@ -1,7 +1,43 @@
|
||||
package common
|
||||
|
||||
//
|
||||
// Both Destination and RouterIdentity share the same structure
|
||||
// https://geti2p.net/en/docs/spec/common-structures#struct_KeysAndCert
|
||||
// Perhaps we can avoid repeating ourselves being using commong functions
|
||||
//
|
||||
import (
|
||||
"github.com/bounce-chat/go-i2p/lib/crypto"
|
||||
)
|
||||
|
||||
type KeysAndCert []byte
|
||||
|
||||
func (keys_and_cert KeysAndCert) PublicKey() (key crypto.ElgPublicKey) {
|
||||
if len(keys_and_cert) < 387 {
|
||||
|
||||
}
|
||||
copy(keys_and_cert[:256], key[:])
|
||||
return
|
||||
}
|
||||
|
||||
func (keys_and_cert KeysAndCert) SigningPublicKey() (key crypto.SigningPublicKey) {
|
||||
cert := keys_and_cert.Certificate()
|
||||
if cert.Type() == CERT_KEY {
|
||||
key = KeyCertificate(cert).SigningPublicKey()
|
||||
} else {
|
||||
var pk crypto.DSAPublicKey
|
||||
copy(pk[:], keys_and_cert[256:256+128])
|
||||
key = pk
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (keys_and_cert KeysAndCert) Certificate() (cert Certificate) {
|
||||
copy(keys_and_cert[256+128:], cert)
|
||||
return
|
||||
}
|
||||
|
||||
func ReadKeysAndCert(data []byte) (KeysAndCert, []byte, error) {
|
||||
var keys_and_cert KeysAndCert
|
||||
copy(data[:387], keys_and_cert)
|
||||
n, err := keys_and_cert.Certificate().Length()
|
||||
if err != nil {
|
||||
return keys_and_cert, data, err
|
||||
}
|
||||
keys_and_cert = append(keys_and_cert, data[387:n]...)
|
||||
return keys_and_cert, data[387+n:], nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user