Skip to content

Commit

Permalink
Cleaned up remaining types for android bindings. Added bindings build…
Browse files Browse the repository at this point in the history
… script
  • Loading branch information
daeMOn63 committed Jan 16, 2020
1 parent 2a876b3 commit 4838bbb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func (np *PubNameAndPassword) PubKey() (e4crypto.Ed25519PublicKey, error) {
return nil, fmt.Errorf("failed to create ed25519 key from password: %v", err)
}

edKey, ok := key.Public().(ed25519.PublicKey)
edKey, ok := ed25519.PrivateKey(key).Public().(ed25519.PublicKey)
if !ok {
return nil, errors.New("failed to cast key to ed25519.PublicKey")
}
Expand Down
12 changes: 6 additions & 6 deletions crypto/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func Decrypt(key, ad, ct []byte) ([]byte, error) {

// Sign will sign the given payload using the given privateKey,
// producing an output composed of: timestamp + signedID + payload + signature
func Sign(signerID []byte, privateKey ed25519.PrivateKey, timestamp []byte, payload []byte) ([]byte, error) {
func Sign(signerID []byte, privateKey Ed25519PrivateKey, timestamp []byte, payload []byte) ([]byte, error) {
if len(signerID) != IDLen {
return nil, ErrInvalidSignerID
}
Expand Down Expand Up @@ -206,7 +206,7 @@ func RandomDelta16() uint16 {
}

// Ed25519PrivateKeyFromPassword creates a ed25519.PrivateKey from a password
func Ed25519PrivateKeyFromPassword(password string) (ed25519.PrivateKey, error) {
func Ed25519PrivateKeyFromPassword(password string) (Ed25519PrivateKey, error) {
if err := ValidatePassword(password); err != nil {
return nil, fmt.Errorf("invalid password: %v", err)
}
Expand All @@ -215,8 +215,8 @@ func Ed25519PrivateKeyFromPassword(password string) (ed25519.PrivateKey, error)
return ed25519.NewKeyFromSeed(seed), nil
}

// PublicEd25519KeyToCurve25519 convert an ed25519.PublicKey to a curve25519 public key.
func PublicEd25519KeyToCurve25519(edPubKey ed25519.PublicKey) Curve25519PublicKey {
// PublicEd25519KeyToCurve25519 convert an Ed25519PublicKey to a Curve25519PublicKey.
func PublicEd25519KeyToCurve25519(edPubKey Ed25519PublicKey) Curve25519PublicKey {
var edPk [ed25519.PublicKeySize]byte
var curveKey [Curve25519PubKeyLen]byte
copy(edPk[:], edPubKey)
Expand All @@ -227,8 +227,8 @@ func PublicEd25519KeyToCurve25519(edPubKey ed25519.PublicKey) Curve25519PublicKe
return curveKey[:]
}

// PrivateEd25519KeyToCurve25519 convert an ed25519.PrivateKey to a curve25519 private key.
func PrivateEd25519KeyToCurve25519(edPrivKey ed25519.PrivateKey) Curve25519PrivateKey {
// PrivateEd25519KeyToCurve25519 convert an Ed25519PrivateKey to a Curve25519PrivateKey.
func PrivateEd25519KeyToCurve25519(edPrivKey Ed25519PrivateKey) Curve25519PrivateKey {
var edSk [ed25519.PrivateKeySize]byte
var curveKey [Curve25519PrivKeyLen]byte
copy(edSk[:], edPrivKey)
Expand Down
16 changes: 16 additions & 0 deletions scripts/bindings.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
# Build android bindings
# Require to have created env variables:
# export ANDROID_HOME=~/Android/Sdk/
# export ANDROID_NDK_HOME=~/Android/Sdk/ndk/21.0.6113669/
# (this is default path where Android Studio is installing the SDK and NDK)

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

OUTDIR="${DIR}/../dist/bindings/android"
# List of packages to include in the generated bindings. (ie: keys is not needed)
INCLUDE_GO_PACKAGES=""

mkdir -p "${OUTDIR}" 2>/dev/null

gomobile bind -v -target android -o "${OUTDIR}/e4.aar" ${DIR}/../ ${DIR}/../crypto

0 comments on commit 4838bbb

Please sign in to comment.