OK before I go any further on this I should go back and check it against the tests.
This commit is contained in:
@ -51,6 +51,7 @@ type CertificateInterface interface {
|
||||
Length() (length int, err error)
|
||||
Data() (data []byte, err error)
|
||||
Type() (cert_type int, err error)
|
||||
SignatureSize() (size int)
|
||||
}
|
||||
|
||||
type Certificate struct {
|
||||
@ -61,6 +62,10 @@ type Certificate struct {
|
||||
|
||||
var ci CertificateInterface = &Certificate{}
|
||||
|
||||
func (certificate Certificate) SignatureSize() (size int) {
|
||||
return 40
|
||||
}
|
||||
|
||||
func (certificate Certificate) Cert() []byte {
|
||||
var ret []byte
|
||||
ret = append(ret, IntegerBytes(certificate.CertType)...)
|
||||
|
@ -31,7 +31,7 @@ func (destination Destination) SigningPublicKey() (crypto.SigningPublicKey, erro
|
||||
return destination.KeysAndCert.GetSigningPublicKey()
|
||||
}
|
||||
|
||||
func (destination Destination) Certificate() (Certificate, error) {
|
||||
func (destination Destination) Certificate() (CertificateInterface, error) {
|
||||
return destination.KeysAndCert.GetCertificate()
|
||||
}
|
||||
|
||||
|
@ -75,6 +75,7 @@ const (
|
||||
)
|
||||
|
||||
type KeyCertificate struct {
|
||||
Certificate
|
||||
PKType int
|
||||
PKExtra []byte
|
||||
SPKType int
|
||||
@ -86,7 +87,7 @@ type KeyCertificate struct {
|
||||
//
|
||||
func (key_certificate KeyCertificate) Data() ([]byte, error) {
|
||||
var r []byte
|
||||
|
||||
r = append(r, key_certificate.Certificate.Cert()...)
|
||||
pk := IntegerBytes(key_certificate.PKType)
|
||||
r = append(r, pk...)
|
||||
spk := IntegerBytes(key_certificate.SPKType)
|
||||
@ -225,6 +226,11 @@ func (key_certificate KeyCertificate) SignatureSize() (size int) {
|
||||
// Read a KeyCertificate from a slice of bytes
|
||||
//
|
||||
func ReadKeyCertificate(data []byte) (key_certificate KeyCertificate, err error) {
|
||||
cert, data, err := ReadCertificate(data)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
key_certificate.Certificate = cert
|
||||
data_len := len(data)
|
||||
if data_len < 2 {
|
||||
log.WithFields(log.Fields{
|
||||
|
@ -68,7 +68,16 @@ type KeysAndCertInterface interface {
|
||||
type KeysAndCert struct {
|
||||
crypto.SigningPublicKey
|
||||
crypto.PublicKey
|
||||
Certificate
|
||||
CertificateInterface
|
||||
}
|
||||
|
||||
func (keys_and_cert KeysAndCert) Bytes() (bytes []byte) { //, err error) {
|
||||
elg_key := keys_and_cert.PublicKey.(crypto.ElgPublicKey)
|
||||
dsa_key := keys_and_cert.SigningPublicKey.(crypto.DSAPublicKey)
|
||||
bytes = append(bytes, dsa_key[:]...)
|
||||
bytes = append(bytes, elg_key[:]...)
|
||||
bytes = append(bytes, keys_and_cert.CertificateInterface.Cert()...)
|
||||
return
|
||||
}
|
||||
|
||||
//
|
||||
@ -113,12 +122,12 @@ func (keys_and_cert KeysAndCert) GetSigningPublicKey() (signing_public_key crypt
|
||||
// Return the Certificate contained in the KeysAndCert and any errors encountered while parsing the
|
||||
// KeysAndCert or Certificate.
|
||||
//
|
||||
func (keys_and_cert KeysAndCert) GetCertificate() (cert Certificate, err error) {
|
||||
_, err = keys_and_cert.Certificate.Type()
|
||||
func (keys_and_cert KeysAndCert) GetCertificate() (cert CertificateInterface, err error) {
|
||||
_, err = keys_and_cert.CertificateInterface.Type()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
cert = keys_and_cert.Certificate
|
||||
cert = keys_and_cert.CertificateInterface
|
||||
return
|
||||
}
|
||||
|
||||
@ -142,15 +151,14 @@ func ReadKeysAndCert(data []byte) (keys_and_cert KeysAndCert, remainder []byte,
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
cert, _ = keys_and_cert.GetCertificate()
|
||||
spk, pk, remainder, err := ReadKeys(data, cert)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
keys_and_cert = KeysAndCert{
|
||||
SigningPublicKey: spk,
|
||||
PublicKey: pk,
|
||||
Certificate: cert,
|
||||
SigningPublicKey: spk,
|
||||
PublicKey: pk,
|
||||
CertificateInterface: cert,
|
||||
}
|
||||
return
|
||||
}
|
||||
@ -221,7 +229,7 @@ func ReadKeys(data []byte, cert CertificateInterface) (spk crypto.SigningPublicK
|
||||
spk = dsa_pk
|
||||
}
|
||||
}
|
||||
cert_len, cert_len_err := cert.Length()
|
||||
cert_len, err := cert.Length()
|
||||
if cert_len == 0 {
|
||||
remainder = data[KEYS_AND_CERT_MIN_SIZE:]
|
||||
return
|
||||
|
@ -97,7 +97,7 @@ func (router_info RouterInfo) IdentHash() (h Hash, err error) {
|
||||
var ri RouterIdentity
|
||||
ri, err = router_info.RouterIdentity()
|
||||
if err == nil {
|
||||
h = HashData(ri)
|
||||
h = HashData(ri.Bytes())
|
||||
}
|
||||
return
|
||||
}
|
||||
@ -210,7 +210,7 @@ func (router_info RouterInfo) Signature() (signature Signature) {
|
||||
head := router_info.optionsLocation()
|
||||
size := head + router_info.optionsSize()
|
||||
ident, _ := router_info.RouterIdentity()
|
||||
keyCert := KeyCertificate(ident)
|
||||
keyCert := ident.CertificateInterface //KeyCertificate(ident)
|
||||
sigSize := keyCert.SignatureSize()
|
||||
signature = Signature(router_info[size : size+sigSize])
|
||||
return
|
||||
@ -224,7 +224,7 @@ func (router_info RouterInfo) optionsLocation() (location int) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
location += len(data)
|
||||
location += len(data.Bytes())
|
||||
|
||||
remainder_len := len(remainder)
|
||||
if remainder_len < 9 {
|
||||
|
Reference in New Issue
Block a user