Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(844)

Side by Side Diff: bcrypt/base64.go

Issue 5564059: code review 5564059: go.crypto: initial code (Closed)
Patch Set: diff -r b50a7fb49394 https://code.google.com/p/go.crypto Created 12 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « README ('k') | bcrypt/bcrypt.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package bcrypt
6
7 import "encoding/base64"
8
9 const alphabet = "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567 89"
10
11 var bcEncoding = base64.NewEncoding(alphabet)
12
13 func base64Encode(src []byte) []byte {
14 n := bcEncoding.EncodedLen(len(src))
15 dst := make([]byte, n)
16 bcEncoding.Encode(dst, src)
17 for dst[n-1] == '=' {
18 n--
19 }
20 return dst[:n]
21 }
22
23 func base64Decode(src []byte) ([]byte, error) {
24 numOfEquals := 4 - (len(src) % 4)
25 for i := 0; i < numOfEquals; i++ {
26 src = append(src, '=')
27 }
28
29 dst := make([]byte, bcEncoding.DecodedLen(len(src)))
30 n, err := bcEncoding.Decode(dst, src)
31 if err != nil {
32 return nil, err
33 }
34 return dst[:n], nil
35 }
OLDNEW
« no previous file with comments | « README ('k') | bcrypt/bcrypt.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b