Skip to content

Commit

Permalink
x/crypto/bcrypt: use base64.NoPadding
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderYastrebov committed Oct 17, 2021
1 parent 089bfa5 commit 8add495
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions bcrypt/base64.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,15 @@ import "encoding/base64"

const alphabet = "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"

var bcEncoding = base64.NewEncoding(alphabet)
var bcEncoding = base64.NewEncoding(alphabet).WithPadding(base64.NoPadding)

func base64Encode(src []byte) []byte {
n := bcEncoding.EncodedLen(len(src))
dst := make([]byte, n)
dst := make([]byte, bcEncoding.EncodedLen(len(src)))
bcEncoding.Encode(dst, src)
for dst[n-1] == '=' {
n--
}
return dst[:n]
return dst
}

func base64Decode(src []byte) ([]byte, error) {
numOfEquals := 4 - (len(src) % 4)
for i := 0; i < numOfEquals; i++ {
src = append(src, '=')
}

dst := make([]byte, bcEncoding.DecodedLen(len(src)))
n, err := bcEncoding.Decode(dst, src)
if err != nil {
Expand Down

0 comments on commit 8add495

Please sign in to comment.