Skip to content

Commit

Permalink
check for secret byte length
Browse files Browse the repository at this point in the history
  • Loading branch information
Alesfatalis committed May 4, 2024
1 parent c7247cc commit 107926a
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions secretkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package ergo
*/
import "C"
import (
"errors"
"runtime"
"unsafe"
)
Expand Down Expand Up @@ -36,7 +37,12 @@ func NewSecretKey() SecretKey {
}

// NewSecretKeyFromBytes parses dlog secret key from bytes (SEC-1-encoded scalar)
// provided secret key bytes must be of length 32
func NewSecretKeyFromBytes(bytes []byte) (SecretKey, error) {
if len(bytes) != 32 {
return nil, errors.New("secret key size must be 32 bytes")
}

byteData := C.CBytes(bytes)
defer C.free(unsafe.Pointer(byteData))

Expand Down

0 comments on commit 107926a

Please sign in to comment.