aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2017-04-10 06:56:07 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2017-04-10 06:56:07 +0800
commit523fe6a83492775f50dfd3c3adbf9699e7fc8e1e (patch)
tree413bfb1ff16517d5c1fb673c914bb390ba07a5f5
parentab601f08e7b805157a0fa7ce162816c0157c89cb (diff)
downloaddexon-bls-523fe6a83492775f50dfd3c3adbf9699e7fc8e1e.tar
dexon-bls-523fe6a83492775f50dfd3c3adbf9699e7fc8e1e.tar.gz
dexon-bls-523fe6a83492775f50dfd3c3adbf9699e7fc8e1e.tar.bz2
dexon-bls-523fe6a83492775f50dfd3c3adbf9699e7fc8e1e.tar.lz
dexon-bls-523fe6a83492775f50dfd3c3adbf9699e7fc8e1e.tar.xz
dexon-bls-523fe6a83492775f50dfd3c3adbf9699e7fc8e1e.tar.zst
dexon-bls-523fe6a83492775f50dfd3c3adbf9699e7fc8e1e.zip
use []byte instead of string
-rw-r--r--go/blscgo/bls.go33
1 files changed, 15 insertions, 18 deletions
diff --git a/go/blscgo/bls.go b/go/blscgo/bls.go
index 7943b95..009ab20 100644
--- a/go/blscgo/bls.go
+++ b/go/blscgo/bls.go
@@ -112,25 +112,24 @@ func (sec *SecretKey) SetStr(s string) error {
}
// SetData --
-func (sec *SecretKey) SetData(s string) error {
- buf := []byte(s)
+func (sec *SecretKey) SetData(buf []byte) error {
// #nosec
err := C.blsSecretKeySetData(sec.getPointer(), (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
if err > 0 {
- return fmt.Errorf("bad string:%s", s)
+ return fmt.Errorf("bad buf:%s", buf)
}
return nil
}
// GetData --
-func (sec *SecretKey) GetData() string {
+func (sec *SecretKey) GetData() []byte {
fpSize := GetOpUnitSize() * 8
buf := make([]byte, fpSize)
n := C.blsSecretKeyGetData(sec.getPointer(), (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
- if n == 0 {
+ if n != C.size_t(fpSize) {
panic("implementation err. size of buf is small")
}
- return string(buf[:n])
+ return buf
}
// IsSame --
@@ -229,25 +228,24 @@ func (pub *PublicKey) SetStr(s string) error {
}
// SetData --
-func (sec *PublicKey) SetData(s string) error {
- buf := []byte(s)
+func (sec *PublicKey) SetData(buf []byte) error {
// #nosec
err := C.blsPublicKeySetData(sec.getPointer(), (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
if err > 0 {
- return fmt.Errorf("bad string:%s", s)
+ return fmt.Errorf("bad buf:%s", buf)
}
return nil
}
// GetData --
-func (sec *PublicKey) GetData() string {
+func (sec *PublicKey) GetData() []byte {
fpSize := GetOpUnitSize() * 8
buf := make([]byte, fpSize*2)
n := C.blsPublicKeyGetData(sec.getPointer(), (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
- if n == 0 {
+ if n != C.size_t(fpSize * 2) {
panic("implementation err. size of buf is small")
}
- return string(buf[:n])
+ return buf
}
// IsSame --
@@ -304,25 +302,24 @@ func (sign *Sign) SetStr(s string) error {
}
// SetData --
-func (sec *Sign) SetData(s string) error {
- buf := []byte(s)
+func (sec *Sign) SetData(buf []byte) error {
// #nosec
err := C.blsSignSetData(sec.getPointer(), (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
if err > 0 {
- return fmt.Errorf("bad string:%s", s)
+ return fmt.Errorf("bad buf:%s", buf)
}
return nil
}
// GetData --
-func (sec *Sign) GetData() string {
+func (sec *Sign) GetData() []byte {
fpSize := GetOpUnitSize() * 8
buf := make([]byte, fpSize)
n := C.blsSignGetData(sec.getPointer(), (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
- if n == 0 {
+ if n != C.size_t(fpSize) {
panic("implementation err. size of buf is small")
}
- return string(buf[:n])
+ return buf
}
// IsSame --