testing and improvements to the common data structures

This commit is contained in:
Hayden Parker
2016-02-05 02:23:11 -08:00
parent f5e806dd14
commit b3fa7082cf
24 changed files with 551 additions and 235 deletions

View File

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