示例#1
0
文件: signer.go 项目: ncw/GoAWS
// SignBytes, but will base64 encode based on the specified encoder.
func (self *Signer) SignEncoded(h crypto.Hash, s string, e *base64.Encoding) (out []byte, err error) {
	ob, err := self.SignBytes(h, bytes.NewBufferString(s).Bytes())
	if err == nil {
		out = make([]byte, e.EncodedLen(len(ob)))
		e.Encode(out, ob)
	}
	return
}
示例#2
0
// SignBytes, but will base64 encode based on the specified encoder.
func (p *signer) SignEncoded(h crypto.Hash, s string, enc *base64.Encoding) (signature []byte, err os.Error) {
	buf, err := p.SignBytes(h, bytes.NewBufferString(s).Bytes())
	if err == nil {
		signature = make([]byte, enc.EncodedLen(len(buf)))
		enc.Encode(signature, buf)
	}
	return
}
示例#3
0
文件: base64.go 项目: dvln/util
// Encode makes it a bit easier to deal with base 64 encoding, see
// example code below.
func Encode(encBuf, bin []byte, e64 *base64.Encoding) []byte {
	maxEncLen := e64.EncodedLen(len(bin))
	if encBuf == nil || len(encBuf) < maxEncLen {
		encBuf = make([]byte, maxEncLen)
	}
	e64.Encode(encBuf, bin)
	return encBuf[0:]
}
示例#4
0
// Sign a string with a specified signer and base64 encoding
func Sign64(s Signer, e *base64.Encoding, sts []byte) (out []byte, err os.Error) {
	sig, err := s.Sign(sts)
	if err != nil {
		return
	}
	out = make([]byte, e.EncodedLen(len(sig)))
	e.Encode(out, sig)
	return
}
示例#5
0
func Sign64Mech(mech string, s SignerMultiMech, e *base64.Encoding, sts []byte) (out []byte, err os.Error) {
	sig, err := s.Sign(mech, sts)
	if err != nil {
		return
	}
	out = make([]byte, e.EncodedLen(len(sig)))
	e.Encode(out, sig)
	return
}
示例#6
0
// Sign a string with a specified signer and base64 encoding
func Sign64(s Signer, e *base64.Encoding,
	ss Signable) (out []byte, err os.Error) {

	sig, err := s.Sign(ss)
	if err != nil {
		return
	}
	bb := sig.SignatureBytes()
	out = make([]byte, e.EncodedLen(len(bb)))
	e.Encode(out, bb)
	return
}
示例#7
0
func Base64Encode(enc *base64.Encoding, src []byte) []byte {
	l := len(src)
	dst := make([]byte, enc.EncodedLen(l))
	enc.Encode(dst, src)
	return dst
}