diff --git a/include/skyassert.h b/include/skyassert.h index ea05ff12a..4ee92d2b8 100644 --- a/include/skyassert.h +++ b/include/skyassert.h @@ -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); diff --git a/lib/cgo/cipher.base58.base58.go b/lib/cgo/cipher.base58.base58.go index 082e8cecf..04dca2a9c 100644 --- a/lib/cgo/cipher.base58.base58.go +++ b/lib/cgo/cipher.base58.base58.go @@ -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 @@ -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 @@ -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 diff --git a/lib/cgo/cipher.bip32.bip32.go b/lib/cgo/cipher.bip32.bip32.go index 20c3ab0b0..8d2e0c39c 100644 --- a/lib/cgo/cipher.bip32.bip32.go +++ b/lib/cgo/cipher.bip32.bip32.go @@ -1,6 +1,7 @@ package main import ( + "reflect" "unsafe" "github.com/skycoin/skycoin/src/cipher/bip32" @@ -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 } @@ -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 } @@ -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 } @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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 } diff --git a/lib/cgo/cipher.bip39.bip39.go b/lib/cgo/cipher.bip39.bip39.go index ede495c7c..28f61a554 100644 --- a/lib/cgo/cipher.bip39.bip39.go +++ b/lib/cgo/cipher.bip39.bip39.go @@ -1,6 +1,7 @@ package main import ( + "reflect" "unsafe" "github.com/skycoin/skycoin/src/cipher/bip39" @@ -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 } diff --git a/lib/cgo/cipher.bip44.bip44.go b/lib/cgo/cipher.bip44.bip44.go index 92192d099..5afa95cc0 100644 --- a/lib/cgo/cipher.bip44.bip44.go +++ b/lib/cgo/cipher.bip44.bip44.go @@ -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 { @@ -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 } diff --git a/lib/cgo/tests/check_cipher.bip32.bip32.c b/lib/cgo/tests/check_cipher.bip32.bip32.c index fd4b52f24..1ecfd1ede 100755 --- a/lib/cgo/tests/check_cipher.bip32.bip32.c +++ b/lib/cgo/tests/check_cipher.bip32.bip32.c @@ -653,22 +653,26 @@ END_TEST START_TEST(TestParentPublicChildDerivation) { - GoSlice extendedMasterPublicBytes; + GoSlice_ extendedMasterPublicBytes_tmp; GoString tmp_str = {"xpub6DxSCdWu6jKqr4isjo7bsPeDD6s3J4YVQV1JSHZg12Eagdqnf7XX4fxqyW2sLhUoFWutL7tAELU2LiGZrEXtjVbvYptvTX5Eoa4Mamdjm9u", 111}; - GoUint32 err = SKY_base58_Decode(tmp_str, &extendedMasterPublicBytes); + GoUint32 err = SKY_base58_Decode(tmp_str, &extendedMasterPublicBytes_tmp); ck_assert_int_eq(err, SKY_OK); PublicKey__Handle extendedMasterPublic = 0; + GoSlice extendedMasterPublicBytes; + copyGoSlice_toGoSlice(&extendedMasterPublicBytes, &extendedMasterPublicBytes_tmp, extendedMasterPublicBytes_tmp.len); err = SKY_bip32_DeserializePublicKey(extendedMasterPublicBytes, &extendedMasterPublic); ck_assert_int_eq(err, SKY_OK); - GoSlice extendedMasterPrivateBytes; + GoSlice extendedMasterPrivateBytes_tmp; tmp_str.p = "xprv9zy5o7z1GMmYdaeQdmabWFhUf52Ytbpe3G5hduA4SghboqWe7aDGWseN8BJy1GU72wPjkCbBE1hvbXYqpCecAYdaivxjNnBoSNxwYD4wHpW"; tmp_str.n = 111; - err = SKY_base58_Decode(tmp_str, &extendedMasterPrivateBytes); + err = SKY_base58_Decode(tmp_str, &extendedMasterPrivateBytes_tmp); ck_assert_int_eq(err, SKY_OK); PrivateKey__Handle extendedMasterPrivate = 0; + GoSlice extendedMasterPrivateBytes; + copyGoSlice_toGoSlice(&extendedMasterPrivateBytes, &extendedMasterPrivateBytes_tmp, extendedMasterPrivateBytes_tmp.len); err = SKY_bip32_DeserializePrivateKey(extendedMasterPrivateBytes, &extendedMasterPrivate); ck_assert_int_eq(err, SKY_OK); @@ -830,13 +834,16 @@ START_TEST(TestParentPublicChildDerivation) ck_assert_int_eq(err, SKY_OK); err = SKY_bip32_PublicKey_NewPublicChildKey(extendedMasterPublic, element_tmp.ChildNumber, &pubKey); ck_assert_int_eq(err, SKY_OK); - GoSlice pubkey_key; - err = SKY_bip32_PublicKey_GetKey(pubKey, &pubkey_key); + GoSlice_ pubkey_key_tmp; + err = SKY_bip32_PublicKey_GetKey(pubKey, &pubkey_key_tmp); ck_assert_int_eq(err, SKY_OK); - GoString pubkey_hexpubkey; + GoString_ pubkey_hexpubkey; + GoSlice pubkey_key; + copyGoSlice_toGoSlice(&pubkey_key, &pubkey_key_tmp, pubkey_key_tmp.len); err = SKY_base58_Hex2String(pubkey_key, &pubkey_hexpubkey); - ck_assert(isGoStringEq(child.hexPubKey, pubkey_hexpubkey)); + ck_assert_int_eq(err, SKY_OK); + ck_assert(isGoString_toGoStringEq(pubkey_hexpubkey, child.hexPubKey)); PublicKey__Handle pubKey2 = 0; err = SKY_bip32_PrivateKey_NewPublicChildKey(extendedMasterPrivate, element_tmp.ChildNumber, &pubKey2); @@ -946,11 +953,13 @@ START_TEST(TestDeserializePrivateInvalidStrings) for (size_t i = 0; i < 12; i++) { tests_Struct test = tests[i]; GoUint8 bufferb[MAXBUFFER]; - GoSlice b = {bufferb, 0, MAXBUFFER}; - GoUint32 err = SKY_base58_Decode(test.base58, &b); + GoSlice_ b_tmp = {bufferb, 0, MAXBUFFER}; + GoUint32 err = SKY_base58_Decode(test.base58, &b_tmp); ck_assert_int_eq(err, SKY_OK); PrivateKey__Handle rest_priv = 0; + GoSlice b; + copyGoSlice_toGoSlice(&b, &b_tmp, b_tmp.len); err = SKY_bip32_DeserializePrivateKey(b, &rest_priv); ck_assert_int_eq(err, test.err); } @@ -1000,11 +1009,13 @@ START_TEST(TestDeserializePublicInvalidStrings) for (size_t i = 0; i < 9; i++) { tests_Struct test = tests[i]; GoUint8 bufferb[MAXBUFFER]; - GoSlice b = {bufferb, 0, MAXBUFFER}; - GoUint32 err = SKY_base58_Decode(test.base58, &b); + GoSlice_ b_tmp = {bufferb, 0, MAXBUFFER}; + GoUint32 err = SKY_base58_Decode(test.base58, &b_tmp); ck_assert_msg(err == SKY_OK, " Iter %d", i); PublicKey__Handle rest_pub = 0; + GoSlice b; + copyGoSlice_toGoSlice(&b, &b_tmp, b_tmp.len); err = SKY_bip32_DeserializePublicKey(b, &rest_pub); ck_assert_msg(err == test.err, "Iter %d", i); } @@ -1092,19 +1103,21 @@ START_TEST(TestNewPrivateKeyFromPath) for (size_t i = 0; i < 4; i++) { cases_Str tc = cases[i]; GoUint8 bufferseed[MAXBUFFER]; - GoSlice seed = {bufferseed, 0, MAXBUFFER}; - GoUint32 err = SKY_base58_String2Hex(tc.seed, &seed); + GoSlice_ seed_tmp = {bufferseed, 0, MAXBUFFER}; + GoUint32 err = SKY_base58_String2Hex(tc.seed, &seed_tmp); ck_assert(err == SKY_OK); PrivateKey__Handle k = 0; + GoSlice seed; + copyGoSlice_toGoSlice(&seed, &seed_tmp, seed_tmp.len); err = SKY_bip32_NewPrivateKeyFromPath(seed, tc.path, &k); ck_assert(err == tc.err); if (err == SKY_OK) { GoUint8 bufferk_string[MAXBUFFER]; - GoString k_string = {bufferk_string, 0}; + GoString_ k_string = {bufferk_string, 0}; err = SKY_bip32_PrivateKey_String(k, &k_string); ck_assert(err == SKY_OK); - ck_assert(isGoStringEq(tc.key, k_string)); + ck_assert(isGoString_toGoStringEq(k_string, tc.key)); } } } diff --git a/lib/cgo/tests/testutils/libsky_assert.c b/lib/cgo/tests/testutils/libsky_assert.c index 7baffd43d..6513ce8a3 100644 --- a/lib/cgo/tests/testutils/libsky_assert.c +++ b/lib/cgo/tests/testutils/libsky_assert.c @@ -38,11 +38,6 @@ GoInt isBitcoinAddressEq(cipher__BitcoinAddress* addr1, cipher__BitcoinAddress* return (addr1->Version == addr2->Version && isRipemd160Eq(&addr1->Key, &addr2->Key)); } -GoInt isGoString_Eq(GoString_ string1, GoString_ string2) -{ - return (string1.n == string2.n) && - (strcmp(string1.p, string2.p) == 0); -} GoInt isSecKeyEq(cipher__SecKey* seckey1, cipher__SecKey* seckey2) { @@ -170,22 +165,22 @@ GoInt isPrivateKeyEq(PrivateKey__Handle handle1, PrivateKey__Handle handle2) { GoUint8 bufferVersion1[1024]; GoUint8 bufferVersion2[1024]; - GoSlice Version1 = {bufferVersion1, 0, 1024}; - GoSlice Version2 = {bufferVersion2, 0, 1024}; + GoSlice_ Version1 = {bufferVersion1, 0, 1024}; + GoSlice_ Version2 = {bufferVersion2, 0, 1024}; GoUint8 bufferParentFingerprint1[1024]; GoUint8 bufferParentFingerprint2[1024]; - GoSlice ParentFingerprint1 = {bufferParentFingerprint1, 0, 1024}; - GoSlice ParentFingerprint2 = {bufferParentFingerprint2, 0, 1024}; + GoSlice_ ParentFingerprint1 = {bufferParentFingerprint1, 0, 1024}; + GoSlice_ ParentFingerprint2 = {bufferParentFingerprint2, 0, 1024}; GoUint32 childNumber1; GoUint32 childNumber2; GoUint8 bufferChainCode1[1024]; GoUint8 bufferChainCode2[1024]; - GoSlice ChainCode1 = {bufferChainCode1, 0, 1024}; - GoSlice ChainCode2 = {bufferChainCode2, 0, 1024}; + GoSlice_ ChainCode1 = {bufferChainCode1, 0, 1024}; + GoSlice_ ChainCode2 = {bufferChainCode2, 0, 1024}; GoUint8 bufferKey1[1024]; GoUint8 bufferKey2[1024]; - GoSlice Key1 = {bufferKey1, 0, 1024}; - GoSlice Key2 = {bufferKey2, 0, 1024}; + GoSlice_ Key1 = {bufferKey1, 0, 1024}; + GoSlice_ Key2 = {bufferKey2, 0, 1024}; GoUint8 Depth1; GoUint8 Depth2; @@ -193,7 +188,7 @@ GoInt isPrivateKeyEq(PrivateKey__Handle handle1, PrivateKey__Handle handle2) ck_assert_int_eq(err, SKY_OK); err = SKY_bip32_PrivateKey_GetVersion(handle2, &Version2); ck_assert_int_eq(err, SKY_OK); - if (!isGoSliceEq(&Version1, &Version2)) { + if (!isGoSlice_Eq(&Version1, &Version2)) { printf("Version not equal\n"); return 0; } @@ -211,7 +206,7 @@ GoInt isPrivateKeyEq(PrivateKey__Handle handle1, PrivateKey__Handle handle2) ck_assert_int_eq(err, SKY_OK); err = SKY_bip32_PrivateKey_GetParentFingerprint(handle2, &ParentFingerprint2); ck_assert_int_eq(err, SKY_OK); - if (!isGoSliceEq(&ParentFingerprint1, &ParentFingerprint2)) { + if (!isGoSlice_Eq(&ParentFingerprint1, &ParentFingerprint2)) { printf("ParentFingerprint not equal\n"); return 0; } @@ -229,7 +224,7 @@ GoInt isPrivateKeyEq(PrivateKey__Handle handle1, PrivateKey__Handle handle2) ck_assert_int_eq(err, SKY_OK); err = SKY_bip32_PrivateKey_GetChainCode(handle2, &ChainCode2); ck_assert_int_eq(err, SKY_OK); - if (!isGoSliceEq(&ChainCode1, &ChainCode2)) { + if (!isGoSlice_Eq(&ChainCode1, &ChainCode2)) { printf("ChainCode not equal\n"); return 0; } @@ -238,7 +233,7 @@ GoInt isPrivateKeyEq(PrivateKey__Handle handle1, PrivateKey__Handle handle2) ck_assert_int_eq(err, SKY_OK); err = SKY_bip32_PrivateKey_GetKey(handle2, &Key2); ck_assert_int_eq(err, SKY_OK); - if (!isGoSliceEq(&Key1, &Key2)) { + if (!isGoSlice_Eq(&Key1, &Key2)) { printf("Key not equal\n"); return 0; } @@ -248,16 +243,24 @@ GoInt isPrivateKeyEq(PrivateKey__Handle handle1, PrivateKey__Handle handle2) GoInt isPublicKeyEq(PublicKey__Handle handle1, PublicKey__Handle handle2) { - GoSlice Version1; - GoSlice Version2; - GoSlice ParentFingerprint1; - GoSlice ParentFingerprint2; + GoUint8 bufferVersion1[1024]; + GoUint8 bufferVersion2[1024]; + GoSlice_ Version1 = {bufferVersion1, 0, 1024}; + GoSlice_ Version2 = {bufferVersion2, 0, 1024}; + GoUint8 bufferParentFingerprint1[1024]; + GoUint8 bufferParentFingerprint2[1024]; + GoSlice_ ParentFingerprint1 = {bufferParentFingerprint1, 0, 1024}; + GoSlice_ ParentFingerprint2 = {bufferParentFingerprint2, 0, 1024}; GoUint32 childNumber1; GoUint32 childNumber2; - GoSlice ChainCode1; - GoSlice ChainCode2; - GoSlice Key1; - GoSlice Key2; + GoUint8 bufferChainCode1[1024]; + GoUint8 bufferChainCode2[1024]; + GoSlice_ ChainCode1 = {bufferChainCode1, 0, 1024}; + GoSlice_ ChainCode2 = {bufferChainCode2, 0, 1024}; + GoUint8 bufferKey1[1024]; + GoUint8 bufferKey2[1024]; + GoSlice_ Key1 = {bufferKey1, 0, 1024}; + GoSlice_ Key2 = {bufferKey2, 0, 1024}; GoUint8 Depth1; GoUint8 Depth2; @@ -265,7 +268,7 @@ GoInt isPublicKeyEq(PublicKey__Handle handle1, PublicKey__Handle handle2) ck_assert_int_eq(err, SKY_OK); err = SKY_bip32_PublicKey_GetVersion(handle2, &Version2); ck_assert_int_eq(err, SKY_OK); - if (!isGoSliceEq(&Version1, &Version2)) { + if (!isGoSlice_Eq(&Version1, &Version2)) { return 0; } @@ -281,7 +284,7 @@ GoInt isPublicKeyEq(PublicKey__Handle handle1, PublicKey__Handle handle2) ck_assert_int_eq(err, SKY_OK); err = SKY_bip32_PublicKey_GetParentFingerprint(handle2, &ParentFingerprint2); ck_assert_int_eq(err, SKY_OK); - if (!isGoSliceEq(&ParentFingerprint1, &ParentFingerprint2)) { + if (!isGoSlice_Eq(&ParentFingerprint1, &ParentFingerprint2)) { return 0; } @@ -297,7 +300,7 @@ GoInt isPublicKeyEq(PublicKey__Handle handle1, PublicKey__Handle handle2) ck_assert_int_eq(err, SKY_OK); err = SKY_bip32_PublicKey_GetChainCode(handle2, &ChainCode2); ck_assert_int_eq(err, SKY_OK); - if (!isGoSliceEq(&ChainCode1, &ChainCode2)) { + if (!isGoSlice_Eq(&ChainCode1, &ChainCode2)) { return 0; } @@ -305,7 +308,7 @@ GoInt isPublicKeyEq(PublicKey__Handle handle1, PublicKey__Handle handle2) ck_assert_int_eq(err, SKY_OK); err = SKY_bip32_PublicKey_GetKey(handle2, &Key2); ck_assert_int_eq(err, SKY_OK); - if (!isGoSliceEq(&Key1, &Key2)) { + if (!isGoSlice_Eq(&Key1, &Key2)) { return 0; } diff --git a/lib/cgo/tests/testutils/libsky_assert.common.c b/lib/cgo/tests/testutils/libsky_assert.common.c index d865a2221..38d4d09dd 100644 --- a/lib/cgo/tests/testutils/libsky_assert.common.c +++ b/lib/cgo/tests/testutils/libsky_assert.common.c @@ -14,6 +14,18 @@ GoInt isGoStringEq(GoString string1, GoString string2) (strncmp(string1.p, string2.p, string1.n) == 0); } +GoInt isGoString_Eq(GoString_ string1, GoString_ string2) +{ + return (string1.n == string2.n) && + (strncmp(string1.p, string2.p, string1.n) == 0); +} + +GoInt isGoString_toGoStringEq(GoString_ string1, GoString string2) +{ + return (string1.n == string2.n) && + (strncmp(string1.p, string2.p, string2.n) == 0); +} + GoInt isPubKeyEq(cipher__PubKey* pubkey1, cipher__PubKey* pubkey2) { return isU8Eq(*pubkey1, *pubkey2, sizeof(cipher__PubKey));