Beispiel #1
0
// Decode makes it a bit easier to deal with base 64 decoding, see
// example code below.
func Decode(decBuf, enc []byte, e64 *base64.Encoding) []byte {
	maxDecLen := e64.DecodedLen(len(enc))
	if decBuf == nil || len(decBuf) < maxDecLen {
		decBuf = make([]byte, maxDecLen)
	}
	n, err := e64.Decode(decBuf, enc)
	_ = err
	return decBuf[0:n]
}
Beispiel #2
0
func Base64Decode(enc *base64.Encoding, src []byte) ([]byte, error) {
	l := len(src)
	dst := make([]byte, enc.DecodedLen(l))
	l, err := enc.Decode(dst, src)
	if err != nil {
		return nil, err
	}

	return dst[:l], nil
}