2016-01-29 07:35:17 -05:00
|
|
|
package common
|
2016-01-28 12:58:58 -05:00
|
|
|
|
2016-02-14 23:10:37 -08:00
|
|
|
/*
|
|
|
|
I2P Destination
|
2016-06-16 23:17:21 -07:00
|
|
|
https://geti2p.net/spec/common-structures#destination
|
2016-02-14 23:10:37 -08:00
|
|
|
Accurate for version 0.9.24
|
|
|
|
|
|
|
|
Identical to KeysAndCert
|
|
|
|
*/
|
|
|
|
|
2016-01-29 07:22:31 -05:00
|
|
|
import (
|
|
|
|
"github.com/bounce-chat/go-i2p/lib/common/base32"
|
|
|
|
"github.com/bounce-chat/go-i2p/lib/common/base64"
|
|
|
|
"github.com/bounce-chat/go-i2p/lib/crypto"
|
|
|
|
"strings"
|
2016-01-28 15:11:54 -05:00
|
|
|
)
|
|
|
|
|
2016-02-14 22:40:29 -08:00
|
|
|
//
|
|
|
|
// A Destination is a KeysAndCert with functionallity
|
|
|
|
// for generating base32 and base64 addresses.
|
|
|
|
//
|
2016-01-28 12:58:58 -05:00
|
|
|
type Destination []byte
|
|
|
|
|
2016-02-13 21:00:29 -08:00
|
|
|
func (destination Destination) PublicKey() (crypto.PublicKey, error) {
|
2016-02-05 02:23:11 -08:00
|
|
|
return KeysAndCert(destination).PublicKey()
|
2016-01-28 12:58:58 -05:00
|
|
|
}
|
|
|
|
|
2016-02-07 02:54:02 -08:00
|
|
|
func (destination Destination) SigningPublicKey() (crypto.SigningPublicKey, error) {
|
2016-02-05 02:23:11 -08:00
|
|
|
return KeysAndCert(destination).SigningPublicKey()
|
2016-01-28 12:58:58 -05:00
|
|
|
}
|
|
|
|
|
2016-02-07 02:54:02 -08:00
|
|
|
func (destination Destination) Certificate() (Certificate, error) {
|
2016-02-05 02:23:11 -08:00
|
|
|
return KeysAndCert(destination).Certificate()
|
2016-01-28 12:58:58 -05:00
|
|
|
}
|
2016-01-28 15:32:09 -05:00
|
|
|
|
2016-02-15 00:34:29 -08:00
|
|
|
func ReadDestination(data []byte) (destination Destination, remainder []byte, err error) {
|
|
|
|
keys_and_cert, remainder, err := ReadKeysAndCert(data)
|
|
|
|
destination = Destination(keys_and_cert)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-02-14 22:40:29 -08:00
|
|
|
//
|
|
|
|
// Generate the I2P base32 address for this Destination.
|
|
|
|
//
|
|
|
|
func (destination Destination) Base32Address() (str string) {
|
2016-02-05 02:23:11 -08:00
|
|
|
hash := crypto.SHA256(destination)
|
2016-02-14 22:40:29 -08:00
|
|
|
str = strings.Trim(base32.EncodeToString(hash[:]), "=")
|
|
|
|
str = str + ".b32.i2p"
|
|
|
|
return
|
2016-01-28 15:32:09 -05:00
|
|
|
}
|
|
|
|
|
2016-02-14 22:40:29 -08:00
|
|
|
//
|
|
|
|
// Generate the I2P base64 address for this Destination.
|
|
|
|
//
|
2016-02-05 02:23:11 -08:00
|
|
|
func (destination Destination) Base64() string {
|
|
|
|
return base64.EncodeToString(destination)
|
2016-01-28 15:32:09 -05:00
|
|
|
}
|