From 4838bbbce5d387a775dd7e128efec1bff524542f Mon Sep 17 00:00:00 2001 From: Flavien binet Date: Thu, 16 Jan 2020 19:49:38 +0100 Subject: [PATCH] Cleaned up remaining types for android bindings. Added bindings build script --- client.go | 2 +- crypto/crypto.go | 12 ++++++------ scripts/bindings.sh | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 7 deletions(-) create mode 100755 scripts/bindings.sh diff --git a/client.go b/client.go index 310b7bf..25025bd 100644 --- a/client.go +++ b/client.go @@ -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") } diff --git a/crypto/crypto.go b/crypto/crypto.go index cfd5553..d9289e8 100644 --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -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 } @@ -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) } @@ -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) @@ -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) diff --git a/scripts/bindings.sh b/scripts/bindings.sh new file mode 100755 index 0000000..97b06d4 --- /dev/null +++ b/scripts/bindings.sh @@ -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