Files
go-i2p/lib/common/destination.go

58 lines
1.4 KiB
Go
Raw Normal View History

package common
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-02-14 22:40:29 -08:00
//
// A Destination is a KeysAndCert with functionallity
// for generating base32 and base64 addresses.
//
type Destination []byte
func (destination Destination) PublicKey() (crypto.PublicKey, error) {
return KeysAndCert(destination).PublicKey()
}
2016-02-07 02:54:02 -08:00
func (destination Destination) SigningPublicKey() (crypto.SigningPublicKey, error) {
return KeysAndCert(destination).SigningPublicKey()
}
2016-02-07 02:54:02 -08:00
func (destination Destination) Certificate() (Certificate, error) {
return KeysAndCert(destination).Certificate()
}
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) {
hash := crypto.SHA256(destination)
2016-02-14 22:40:29 -08:00
str = strings.Trim(base32.EncodeToString(hash[:]), "=")
str = str + ".b32.i2p"
return
}
2016-02-14 22:40:29 -08:00
//
// Generate the I2P base64 address for this Destination.
//
func (destination Destination) Base64() string {
return base64.EncodeToString(destination)
}