* add hash.go in crypto package
* add base32 / base64 in destination * add helper functions for base64 / base32
This commit is contained in:
@@ -9,3 +9,10 @@ import (
|
||||
|
||||
// i2p base32 encoding
|
||||
var I2PEncoding *b32.Encoding = b32.NewEncoding("abcdefghijklmnopqrstuvwxyz234567")
|
||||
|
||||
|
||||
// wrapper arround encoding for encoding to string
|
||||
func EncodeToString(data []byte) (str string) {
|
||||
str = I2PEncoding.EncodeToString(data)
|
||||
return
|
||||
}
|
||||
|
@@ -9,3 +9,9 @@ import (
|
||||
|
||||
// i2p base64 encoding
|
||||
var I2PEncoding *b64.Encoding = b64.NewEncoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-~")
|
||||
|
||||
// wrapper arround encoding for encoding to string
|
||||
func EncodeToString(data []byte) (str string) {
|
||||
str = I2PEncoding.EncodeToString(data)
|
||||
return
|
||||
}
|
||||
|
7
lib/crypto/hash.go
Normal file
7
lib/crypto/hash.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package crypto
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
)
|
||||
|
||||
var SHA256 = sha256.Sum256
|
@@ -1,7 +1,10 @@
|
||||
package stdi2p
|
||||
|
||||
import (
|
||||
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"
|
||||
)
|
||||
|
||||
// a network endpoint inside i2p
|
||||
@@ -12,6 +15,7 @@ type Destination []byte
|
||||
func (dest Destination) PublicKey() (k crypto.PublicEncryptionKey) {
|
||||
cert := dest.Certificate()
|
||||
if cert.Type() == CERT_KEY {
|
||||
// TODO(psi): check for key cert and included encryption key
|
||||
} else {
|
||||
var ek crypto.ElgPublicKey
|
||||
copy(ek[:], dest[:256])
|
||||
@@ -31,6 +35,7 @@ func (dest Destination) SigningPublicKey() (k crypto.SigningPublicKey) {
|
||||
cert := dest.Certificate()
|
||||
if cert.Type() == CERT_KEY {
|
||||
// we have a key certificate
|
||||
// extract the signing key from the key cert
|
||||
k = KeyCert(cert).SigningPublicKey()
|
||||
} else {
|
||||
var pk crypto.DSAPublicKey
|
||||
@@ -39,3 +44,16 @@ func (dest Destination) SigningPublicKey() (k crypto.SigningPublicKey) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// return the .b32.i2p address
|
||||
func (dest Destination) Base32Address() (str string) {
|
||||
h := crypto.SHA256(dest)
|
||||
str = strings.Trim(base32.EncodeToString(h[:]), "=")
|
||||
str += ".b32.i2p"
|
||||
return
|
||||
}
|
||||
|
||||
func (dest Destination) Base64() (str string) {
|
||||
str = base64.EncodeToString(dest)
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user