From 51e69f9763a8d7da268c6ebcb6e9678b0dcdfd91 Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Sun, 9 Apr 2017 20:26:11 +0900 Subject: add SetData/GetData/IsSame to bls.cgo --- go/blscgo/bls.go | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) (limited to 'go/blscgo/bls.go') diff --git a/go/blscgo/bls.go b/go/blscgo/bls.go index 5873f38..10892f9 100644 --- a/go/blscgo/bls.go +++ b/go/blscgo/bls.go @@ -106,6 +106,33 @@ func (sec *SecretKey) SetStr(s string) error { return nil } +// SetData -- +func (sec *SecretKey) SetData(s string) error { + buf := []byte(s) + // #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 nil +} + +// GetData -- +func (sec *SecretKey) GetData() string { + 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 { + panic("implementation err. size of buf is small") + } + return string(buf[:n]) +} + +// IsSame -- +func (lhs *SecretKey) IsSame(rhs *SecretKey) bool { + return C.blsSecretKeyIsSame(lhs.getPointer(), rhs.getPointer()) == 1 +} + // SetArray -- func (sec *SecretKey) SetArray(v []uint64) { expect := GetOpUnitSize() @@ -196,6 +223,33 @@ func (pub *PublicKey) SetStr(s string) error { return nil } +// SetData -- +func (sec *PublicKey) SetData(s string) error { + buf := []byte(s) + // #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 nil +} + +// GetData -- +func (sec *PublicKey) GetData() string { + 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 { + panic("implementation err. size of buf is small") + } + return string(buf[:n]) +} + +// IsSame -- +func (lhs *PublicKey) IsSame(rhs *PublicKey) bool { + return C.blsPublicKeyIsSame(lhs.getPointer(), rhs.getPointer()) == 1 +} + // Add -- func (pub *PublicKey) Add(rhs *PublicKey) { C.blsPublicKeyAdd(pub.getPointer(), rhs.getPointer()) @@ -244,6 +298,33 @@ func (sign *Sign) SetStr(s string) error { return nil } +// SetData -- +func (sec *Sign) SetData(s string) error { + buf := []byte(s) + // #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 nil +} + +// GetData -- +func (sec *Sign) GetData() string { + 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 { + panic("implementation err. size of buf is small") + } + return string(buf[:n]) +} + +// IsSame -- +func (lhs *Sign) IsSame(rhs *Sign) bool { + return C.blsSignIsSame(lhs.getPointer(), rhs.getPointer()) == 1 +} + // GetPublicKey -- func (sec *SecretKey) GetPublicKey() (pub *PublicKey) { pub = new(PublicKey) -- cgit v1.2.3