aboutsummaryrefslogtreecommitdiffstats
path: root/go/bls/bls.go
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2016-09-07 05:22:43 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2016-09-07 05:22:43 +0800
commit5fef77491c0ca0cd4895915a7374e9e8b8fb0bc2 (patch)
tree9d8579ef1b2a9d62a0ba84fb3a1eb971a3d51677 /go/bls/bls.go
parentb02d8bff51ff3ee683f8b7ea2cf694f539814610 (diff)
downloaddexon-bls-5fef77491c0ca0cd4895915a7374e9e8b8fb0bc2.tar
dexon-bls-5fef77491c0ca0cd4895915a7374e9e8b8fb0bc2.tar.gz
dexon-bls-5fef77491c0ca0cd4895915a7374e9e8b8fb0bc2.tar.bz2
dexon-bls-5fef77491c0ca0cd4895915a7374e9e8b8fb0bc2.tar.lz
dexon-bls-5fef77491c0ca0cd4895915a7374e9e8b8fb0bc2.tar.xz
dexon-bls-5fef77491c0ca0cd4895915a7374e9e8b8fb0bc2.tar.zst
dexon-bls-5fef77491c0ca0cd4895915a7374e9e8b8fb0bc2.zip
return error if fails
Diffstat (limited to 'go/bls/bls.go')
-rw-r--r--go/bls/bls.go34
1 files changed, 19 insertions, 15 deletions
diff --git a/go/bls/bls.go b/go/bls/bls.go
index fa309ec..e66a062 100644
--- a/go/bls/bls.go
+++ b/go/bls/bls.go
@@ -33,25 +33,26 @@ func (id *Id) String() string {
buf := make([]byte, 1024)
n := C.blsIdGetStr(id.self, (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
if n == 0 {
- return "err"
+ panic("implementation err. size of buf is small")
}
return string(buf[:n])
}
-func (id *Id) SetStr(s string) {
+func (id *Id) SetStr(s string) error {
buf := []byte(s)
err := C.blsIdSetStr(id.self, (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
if err > 0 {
- fmt.Println("Id:SetStr", err)
+ return fmt.Errorf("bad string:%s", s)
}
+ return nil
}
-func (id *Id) Set(v []uint64) {
+func (id *Id) Set(v []uint64) error {
if len(v) != 4 {
- fmt.Println("Id:set bad size", len(v))
- return
+ return fmt.Errorf("bad size", len(v))
}
C.blsIdSet(id.self, (*C.uint64_t)(unsafe.Pointer(&v[0])))
+ return nil
}
type SecretKey struct {
@@ -73,17 +74,18 @@ func (sec *SecretKey) String() string {
buf := make([]byte, 1024)
n := C.blsSecretKeyGetStr(sec.self, (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
if n == 0 {
- return "err"
+ panic("implementation err. size of buf is small")
}
return string(buf[:n])
}
-func (sec *SecretKey) SetStr(s string) {
+func (sec *SecretKey) SetStr(s string) error {
buf := []byte(s)
err := C.blsSecretKeySetStr(sec.self, (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
if err > 0 {
- fmt.Println("SecretKey:SetStr", err)
+ return fmt.Errorf("bad string:%s", s)
}
+ return nil
}
func (sec *SecretKey) Init() {
@@ -166,17 +168,18 @@ func (pub *PublicKey) String() string {
buf := make([]byte, 1024)
n := C.blsPublicKeyGetStr(pub.self, (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
if n == 0 {
- return "err"
+ panic("implementation err. size of buf is small")
}
return string(buf[:n])
}
-func (pub *PublicKey) SetStr(s string) {
+func (pub *PublicKey) SetStr(s string) error {
buf := []byte(s)
err := C.blsPublicKeySetStr(pub.self, (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
if err > 0 {
- fmt.Println("PublicKey:SetStr", err)
+ return fmt.Errorf("bad string:%s", s)
}
+ return nil
}
func (pub *PublicKey) Add(rhs *PublicKey) {
@@ -212,17 +215,18 @@ func (sign *Sign) String() string {
buf := make([]byte, 1024)
n := C.blsSignGetStr(sign.self, (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
if n == 0 {
- return "err"
+ panic("implementation err. size of buf is small")
}
return string(buf[:n])
}
-func (sign *Sign) SetStr(s string) {
+func (sign *Sign) SetStr(s string) error {
buf := []byte(s)
err := C.blsSignSetStr(sign.self, (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
if err > 0 {
- fmt.Println("Sign:SetStr", err)
+ return fmt.Errorf("bad string:%s", s)
}
+ return nil
}
func (sec *SecretKey) GetPublicKey() (pub *PublicKey) {