Skip to content

Commit

Permalink
[cgo][libc][test-libsky] refs fibercrypto#105 correcting memory error…
Browse files Browse the repository at this point in the history
… generated by cipher.bip44 and cipher.32
  • Loading branch information
Maykel Arias Torres committed Sep 27, 2019
1 parent da78c35 commit 2030f0c
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 81 deletions.
2 changes: 2 additions & 0 deletions include/skyassert.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ extern GoInt isGoStringEq(GoString string1, GoString string2);

extern GoInt isGoString_Eq(GoString_ string1, GoString_ string2);

extern GoInt isGoString_toGoStringEq(GoString_ string1, GoString string2);

extern GoInt isPrivateKeyEq(PrivateKey__Handle handle1, PrivateKey__Handle handle2);
extern GoInt isPublicKeyEq(PublicKey__Handle handle1, PublicKey__Handle handle2);

Expand Down
12 changes: 12 additions & 0 deletions lib/cgo/cipher.base58.base58.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import "C"
//export SKY_base58_Hex2Base58
func SKY_base58_Hex2Base58(_val []byte, _arg1 *C.GoString_) (____error_code uint32) {
val := *(*[]byte)(unsafe.Pointer(&_val))
if val == nil {
____error_code = SKY_BAD_HANDLE
return
}
__arg1 := string(base58.Encode(val))
copyString(__arg1, _arg1)
return
Expand All @@ -28,6 +32,10 @@ func SKY_base58_Hex2Base58(_val []byte, _arg1 *C.GoString_) (____error_code uint
//export SKY_base58_Encode
func SKY_base58_Encode(_bin []byte, _arg1 *C.GoString_) (____error_code uint32) {
bin := *(*[]byte)(unsafe.Pointer(&_bin))
if bin == nil {
____error_code = SKY_BAD_HANDLE
return
}
__arg1 := base58.Encode(bin)
copyString(__arg1, _arg1)
return
Expand Down Expand Up @@ -60,6 +68,10 @@ func SKY_base58_String2Hex(_s string, _arg1 *C.GoSlice_) (____error_code uint32)
//export SKY_base58_Hex2String
func SKY_base58_Hex2String(_b []byte, _arg1 *C.GoString_) (____error_code uint32) {
bin := *(*[]byte)(unsafe.Pointer(&_b))
if bin == nil {
____error_code = SKY_BAD_HANDLE
return
}
__arg1 := hex.EncodeToString(bin)
copyString(__arg1, _arg1)
return
Expand Down
80 changes: 48 additions & 32 deletions lib/cgo/cipher.bip32.bip32.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"reflect"
"unsafe"

"github.com/skycoin/skycoin/src/cipher/bip32"
Expand Down Expand Up @@ -68,46 +69,50 @@ func SKY_bip32_PrivateKey_Publickey(_pk C.PrivateKey__Handle, _pp *C.PublicKey__
}

//export SKY_bip32_PrivateKey_Fingerprint
func SKY_bip32_PrivateKey_Fingerprint(_pk C.PrivateKey__Handle, _arg0 *[]byte) (___error_code uint32) {
func SKY_bip32_PrivateKey_Fingerprint(_pk C.PrivateKey__Handle, _arg0 *C.GoSlice_) (___error_code uint32) {
pk, okpk := lookupPrivateKeyHandle(_pk)
if !okpk {
___error_code = SKY_BAD_HANDLE
return
}
*_arg0 = pk.Fingerprint()
__arg0 := pk.Fingerprint()
copyToGoSlice(reflect.ValueOf(__arg0), _arg0)
return
}

//export SKY_bip32_PrivateKey_Identifier
func SKY_bip32_PrivateKey_Identifier(_pk C.PrivateKey__Handle, _arg0 *[]byte) (___error_code uint32) {
func SKY_bip32_PrivateKey_Identifier(_pk C.PrivateKey__Handle, _arg0 *C.GoSlice_) (___error_code uint32) {
pk, okpk := lookupPrivateKeyHandle(_pk)
if !okpk {
___error_code = SKY_BAD_HANDLE
return
}
*_arg0 = pk.Identifier()
__arg0 := pk.Identifier()
copyToGoSlice(reflect.ValueOf(__arg0), _arg0)
return
}

//export SKY_bip32_PublicKey_Fingerprint
func SKY_bip32_PublicKey_Fingerprint(_pk C.PublicKey__Handle, _arg0 *[]byte) (___error_code uint32) {
func SKY_bip32_PublicKey_Fingerprint(_pk C.PublicKey__Handle, _arg0 *C.GoSlice_) (___error_code uint32) {
pk, okpk := lookupPublicKeyHandle(_pk)
if !okpk {
___error_code = SKY_BAD_HANDLE
return
}
*_arg0 = pk.Fingerprint()
__arg0 := pk.Fingerprint()
copyToGoSlice(reflect.ValueOf(__arg0), _arg0)
return
}

//export SKY_bip32_PublicKey_Identifier
func SKY_bip32_PublicKey_Identifier(_pk C.PublicKey__Handle, _arg0 *[]byte) (___error_code uint32) {
func SKY_bip32_PublicKey_Identifier(_pk C.PublicKey__Handle, _arg0 *C.GoSlice_) (___error_code uint32) {
pk, okpk := lookupPublicKeyHandle(_pk)
if !okpk {
___error_code = SKY_BAD_HANDLE
return
}
*_arg0 = pk.Identifier()
__arg0 := pk.Identifier()
copyToGoSlice(reflect.ValueOf(__arg0), _arg0)
return
}

Expand Down Expand Up @@ -157,51 +162,55 @@ func SKY_bip32_PublicKey_NewPublicChildKey(_pk C.PublicKey__Handle, childIdx uin
}

//export SKY_bip32_PrivateKey_Serialize
func SKY_bip32_PrivateKey_Serialize(_pk C.PrivateKey__Handle, _arg0 *[]byte) (___error_code uint32) {
func SKY_bip32_PrivateKey_Serialize(_pk C.PrivateKey__Handle, _arg0 *C.GoSlice_) (___error_code uint32) {
pk, okpk := lookupPrivateKeyHandle(_pk)

if !okpk {
___error_code = SKY_BAD_HANDLE
return
}
*_arg0 = pk.Serialize()
__arg0 := pk.Serialize()
copyToGoSlice(reflect.ValueOf(__arg0), _arg0)

return
}

//export SKY_bip32_PublicKey_Serialize
func SKY_bip32_PublicKey_Serialize(_pk C.PublicKey__Handle, _arg0 *[]byte) (___error_code uint32) {
func SKY_bip32_PublicKey_Serialize(_pk C.PublicKey__Handle, _arg0 *C.GoSlice_) (___error_code uint32) {
pk, okpk := lookupPublicKeyHandle(_pk)

if !okpk {
___error_code = SKY_BAD_HANDLE
return
}
*_arg0 = pk.Serialize()
__arg0 := pk.Serialize()
copyToGoSlice(reflect.ValueOf(__arg0), _arg0)
return
}

//export SKY_bip32_PrivateKey_String
func SKY_bip32_PrivateKey_String(_pk C.PrivateKey__Handle, _arg0 *string) (___error_code uint32) {
func SKY_bip32_PrivateKey_String(_pk C.PrivateKey__Handle, _arg0 *C.GoString_) (___error_code uint32) {
pk, okpk := lookupPrivateKeyHandle(_pk)

if !okpk {
___error_code = SKY_BAD_HANDLE
return
}
*_arg0 = pk.String()
__arg0 := pk.String()
copyString(__arg0, _arg0)
return
}

//export SKY_bip32_PublicKey_String
func SKY_bip32_PublicKey_String(_pk C.PublicKey__Handle, _arg0 *string) (___error_code uint32) {
func SKY_bip32_PublicKey_String(_pk C.PublicKey__Handle, _arg0 *C.GoString_) (___error_code uint32) {
pk, okpk := lookupPublicKeyHandle(_pk)

if !okpk {
___error_code = SKY_BAD_HANDLE
return
}
*_arg0 = pk.String()
__arg0 := pk.String()
copyString(__arg0, _arg0)
return
}

Expand Down Expand Up @@ -248,26 +257,28 @@ func SKY_bip32_DeserializePublicKey(_data []byte, _arg0 *C.PublicKey__Handle) (_
}

//export SKY_bip32_PrivateKey_GetKey
func SKY_bip32_PrivateKey_GetKey(_pk C.PrivateKey__Handle, _arg0 *[]byte) (___error_code uint32) {
func SKY_bip32_PrivateKey_GetKey(_pk C.PrivateKey__Handle, _arg0 *C.GoSlice_) (___error_code uint32) {
pk, okpk := lookupPrivateKeyHandle(_pk)

if !okpk {
___error_code = SKY_BAD_HANDLE
return
}
*_arg0 = pk.Key
__arg0 := pk.Key
copyToGoSlice(reflect.ValueOf(__arg0), _arg0)
return
}

//export SKY_bip32_PublicKey_GetKey
func SKY_bip32_PublicKey_GetKey(_pk C.PublicKey__Handle, _arg0 *[]byte) (___error_code uint32) {
func SKY_bip32_PublicKey_GetKey(_pk C.PublicKey__Handle, _arg0 *C.GoSlice_) (___error_code uint32) {
pk, okpk := lookupPublicKeyHandle(_pk)

if !okpk {
___error_code = SKY_BAD_HANDLE
return
}
*_arg0 = pk.Key
__arg0 := pk.Key
copyToGoSlice(reflect.ValueOf(__arg0), _arg0)
return
}

Expand Down Expand Up @@ -325,7 +336,7 @@ func SKY_bip32_PublicKey_ChildNumber(_pk C.PublicKey__Handle, _arg0 *uint32) (__
}

//export SKY_bip32_PrivateKey_GetChainCode
func SKY_bip32_PrivateKey_GetChainCode(_pk C.PrivateKey__Handle, _arg0 *[]byte) (___error_code uint32) {
func SKY_bip32_PrivateKey_GetChainCode(_pk C.PrivateKey__Handle, _arg0 *C.GoSlice_) (___error_code uint32) {

pk, okpk := lookupPrivateKeyHandle(_pk)

Expand All @@ -334,12 +345,13 @@ func SKY_bip32_PrivateKey_GetChainCode(_pk C.PrivateKey__Handle, _arg0 *[]byte)
return
}

*_arg0 = pk.ChainCode
__arg0 := pk.ChainCode
copyToGoSlice(reflect.ValueOf(__arg0), _arg0)
return
}

//export SKY_bip32_PublicKey_GetChainCode
func SKY_bip32_PublicKey_GetChainCode(_pk C.PublicKey__Handle, _arg0 *[]byte) (___error_code uint32) {
func SKY_bip32_PublicKey_GetChainCode(_pk C.PublicKey__Handle, _arg0 *C.GoSlice_) (___error_code uint32) {

pk, okpk := lookupPublicKeyHandle(_pk)

Expand All @@ -348,12 +360,13 @@ func SKY_bip32_PublicKey_GetChainCode(_pk C.PublicKey__Handle, _arg0 *[]byte) (_
return
}

*_arg0 = pk.ChainCode
__arg0 := pk.ChainCode
copyToGoSlice(reflect.ValueOf(__arg0), _arg0)
return
}

//export SKY_bip32_PrivateKey_GetVersion
func SKY_bip32_PrivateKey_GetVersion(_pk C.PrivateKey__Handle, _arg0 *[]byte) (___error_code uint32) {
func SKY_bip32_PrivateKey_GetVersion(_pk C.PrivateKey__Handle, _arg0 *C.GoSlice_) (___error_code uint32) {

pk, okpk := lookupPrivateKeyHandle(_pk)

Expand All @@ -362,12 +375,13 @@ func SKY_bip32_PrivateKey_GetVersion(_pk C.PrivateKey__Handle, _arg0 *[]byte) (_
return
}

*_arg0 = pk.Version
__arg0 := pk.Version
copyToGoSlice(reflect.ValueOf(__arg0), _arg0)
return
}

//export SKY_bip32_PublicKey_GetVersion
func SKY_bip32_PublicKey_GetVersion(_pk C.PublicKey__Handle, _arg0 *[]byte) (___error_code uint32) {
func SKY_bip32_PublicKey_GetVersion(_pk C.PublicKey__Handle, _arg0 *C.GoSlice_) (___error_code uint32) {

pk, okpk := lookupPublicKeyHandle(_pk)

Expand All @@ -376,12 +390,12 @@ func SKY_bip32_PublicKey_GetVersion(_pk C.PublicKey__Handle, _arg0 *[]byte) (___
return
}

*_arg0 = pk.Version
copyToGoSlice(reflect.ValueOf(pk.Version), _arg0)
return
}

//export SKY_bip32_PrivateKey_GetParentFingerprint
func SKY_bip32_PrivateKey_GetParentFingerprint(_pk C.PrivateKey__Handle, _arg0 *[]byte) (___error_code uint32) {
func SKY_bip32_PrivateKey_GetParentFingerprint(_pk C.PrivateKey__Handle, _arg0 *C.GoSlice_) (___error_code uint32) {

pk, okpk := lookupPrivateKeyHandle(_pk)

Expand All @@ -390,12 +404,13 @@ func SKY_bip32_PrivateKey_GetParentFingerprint(_pk C.PrivateKey__Handle, _arg0 *
return
}

*_arg0 = pk.ParentFingerprint
__arg0 := pk.ParentFingerprint
copyToGoSlice(reflect.ValueOf(__arg0), _arg0)
return
}

//export SKY_bip32_PublicKey_GetParentFingerprint
func SKY_bip32_PublicKey_GetParentFingerprint(_pk C.PublicKey__Handle, _arg0 *[]byte) (___error_code uint32) {
func SKY_bip32_PublicKey_GetParentFingerprint(_pk C.PublicKey__Handle, _arg0 *C.GoSlice_) (___error_code uint32) {

pk, okpk := lookupPublicKeyHandle(_pk)

Expand All @@ -404,6 +419,7 @@ func SKY_bip32_PublicKey_GetParentFingerprint(_pk C.PublicKey__Handle, _arg0 *[]
return
}

*_arg0 = pk.ParentFingerprint
__arg0 := pk.ParentFingerprint
copyToGoSlice(reflect.ValueOf(__arg0), _arg0)
return
}
5 changes: 3 additions & 2 deletions lib/cgo/cipher.bip39.bip39.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"reflect"
"unsafe"

"github.com/skycoin/skycoin/src/cipher/bip39"
Expand Down Expand Up @@ -56,13 +57,13 @@ func SKY_bip39_ValidateMnemonic(_mnemonic string) (____error_code uint32) {
}

//export SKY_bip39_NewSeed
func SKY_bip39_NewSeed(_mnemonic string, _password string, _arg1 *[]byte) (____error_code uint32) {
func SKY_bip39_NewSeed(_mnemonic string, _password string, _arg1 *C.GoSlice_) (____error_code uint32) {
mnemonic := _mnemonic
password := _password
__arg1, ____return_err := bip39.NewSeed(mnemonic, password)
____error_code = libErrorCode(____return_err)
if ____return_err == nil {
*_arg1 = __arg1
copyToGoSlice(reflect.ValueOf(__arg1), _arg1)
}
return
}
5 changes: 3 additions & 2 deletions lib/cgo/cipher.bip44.bip44.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func SKY_bip44_Account_Change(_a C.Account__Handle, _arg0 *C.PrivateKey__Handle)
}

//export SKY_bip44_Account_String
func SKY_bip44_Account_String(_a C.Account__Handle, _arg0 *string) (___err_code uint32) {
func SKY_bip44_Account_String(_a C.Account__Handle, _arg0 *C.GoString_) (___err_code uint32) {

a, oka := lookupAccountHandle(_a)
if !oka {
Expand All @@ -82,7 +82,8 @@ func SKY_bip44_Account_String(_a C.Account__Handle, _arg0 *string) (___err_code
return
}

*_arg0 = a.String()
__arg0 := a.String()
copyString(__arg0, _arg0)
return
}

Expand Down
Loading

0 comments on commit 2030f0c

Please sign in to comment.