Skip to content

Commit

Permalink
RandSlice added
Browse files Browse the repository at this point in the history
  • Loading branch information
techlab-lainio committed Sep 14, 2021
1 parent 5ef0720 commit ab3221e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions crypto/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package crypto

import (
"crypto/ed25519"
"crypto/rand"

"github.com/lainio/err2"
"github.com/lainio/err2/assert"
)

type PubKey = []byte
Expand Down Expand Up @@ -35,6 +37,13 @@ func (k Key) VerifySign(msg []byte, sig Signature) bool {
return VerifySign(k.PubKey, msg, sig)
}

func RandSlice(n int) []byte {
b := make([]byte, n)
r := err2.Int.Try(rand.Read(b))
assert.P.True(r == n)
return b
}

type Signature = []byte

func EqualBytes(a, b []byte) bool {
Expand Down

0 comments on commit ab3221e

Please sign in to comment.