當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Signature.Serialize方法代碼示例

本文整理匯總了Golang中code/google/com/p/go/crypto/openpgp/packet.Signature.Serialize方法的典型用法代碼示例。如果您正苦於以下問題:Golang Signature.Serialize方法的具體用法?Golang Signature.Serialize怎麽用?Golang Signature.Serialize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在code/google/com/p/go/crypto/openpgp/packet.Signature的用法示例。


在下文中一共展示了Signature.Serialize方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Close

func (d *dashEscaper) Close() (err error) {
	if !d.atBeginningOfLine {
		if err = d.buffered.WriteByte(lf); err != nil {
			return
		}
	}
	sig := new(packet.Signature)
	sig.SigType = packet.SigTypeText
	sig.PubKeyAlgo = d.privateKey.PubKeyAlgo
	sig.Hash = d.hashType
	sig.CreationTime = d.config.Now()
	sig.IssuerKeyId = &d.privateKey.KeyId

	if err = sig.Sign(d.h, d.privateKey, d.config); err != nil {
		return
	}

	out, err := armor.Encode(d.buffered, "PGP SIGNATURE", nil)
	if err != nil {
		return
	}

	if err = sig.Serialize(out); err != nil {
		return
	}
	if err = out.Close(); err != nil {
		return
	}
	if err = d.buffered.Flush(); err != nil {
		return
	}
	return
}
開發者ID:postfix,項目名稱:pw,代碼行數:33,代碼來源:clearsign.go

示例2: detachSign

func detachSign(w io.Writer, signer *Entity, message io.Reader, sigType packet.SignatureType, config *packet.Config) (err error) {
	if signer.PrivateKey == nil {
		return errors.InvalidArgumentError("signing key doesn't have a private key")
	}
	if signer.PrivateKey.Encrypted {
		return errors.InvalidArgumentError("signing key is encrypted")
	}

	sig := new(packet.Signature)
	sig.SigType = sigType
	sig.PubKeyAlgo = signer.PrivateKey.PubKeyAlgo
	sig.Hash = config.Hash()
	sig.CreationTime = config.Now()
	sig.IssuerKeyId = &signer.PrivateKey.KeyId

	h, wrappedHash, err := hashForSignature(sig.Hash, sig.SigType)
	if err != nil {
		return
	}
	io.Copy(wrappedHash, message)

	err = sig.Sign(h, signer.PrivateKey, config)
	if err != nil {
		return
	}

	return sig.Serialize(w)
}
開發者ID:Bobberino,項目名稱:musings,代碼行數:28,代碼來源:write.go

示例3: RemoteDetachSign

func RemoteDetachSign(w io.Writer, signer *openpgp.Entity, remoteUrl, path string) error {
	if signer.PrivateKey == nil {
		return errors.InvalidArgumentError("signing key doesn't have a private key")
	}
	if signer.PrivateKey.Encrypted {
		return errors.InvalidArgumentError("signing key is encrypted")
	}

	sig := new(packet.Signature)
	sig.SigType = packet.SigTypeBinary
	sig.PubKeyAlgo = signer.PrivateKey.PubKeyAlgo
	sig.Hash = crypto.SHA256
	sig.CreationTime = time.Now()
	sig.IssuerKeyId = &signer.PrivateKey.KeyId

	// prepare outSubpackets and hash suffix.
	prepareSign(sig)
	pgpSuffix := sig.HashSuffix
	digest, err := RemoteHash(remoteUrl, path, pgpSuffix)
	if err != nil {
		return fmt.Errorf("could not fetch remote hash: %s", err)
	}

	err = MakeSignature(sig, signer.PrivateKey, digest)
	if err != nil {
		return fmt.Errorf("could not build signature: %s", err)
	}

	return sig.Serialize(w)
}
開發者ID:remyoudompheng,項目名稱:remotepgp,代碼行數:30,代碼來源:pgptypes.go


注:本文中的code/google/com/p/go/crypto/openpgp/packet.Signature.Serialize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。