~ubuntu-branches/ubuntu/saucy/juju-core/saucy-proposed

« back to all changes in this revision

Viewing changes to src/code.google.com/p/go.crypto/bcrypt/base64.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-07-11 17:18:27 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130711171827-vjqkg40r0dlf7ys2
Tags: 1.11.2-0ubuntu1
* New upstream release.
* Make juju-core the default juju (LP: #1190634):
  - d/control: Add virtual package juju -> juju-core.
  - d/juju-core.postinst.in: Bump priority of alternatives over that of
    python juju packages.
* Enable for all architectures (LP: #1172505):
  - d/control: Version BD on golang-go to >= 2:1.1.1 to ensure CGO
    support for non-x86 archs, make juju-core Arch: any.
  - d/README.source: Dropped - no longer required.
* d/watch: Updated for new upstream tarball naming.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 = "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
 
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
}