Пример #1
0
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
}
Пример #2
0
func armoredDetachSign(w io.Writer, signer *Entity, message io.Reader, sigType packet.SignatureType, config *packet.Config) (err error) {
	out, err := armor.Encode(w, SignatureType, nil)
	if err != nil {
		return
	}
	err = detachSign(out, signer, message, sigType, config)
	if err != nil {
		return
	}
	return out.Close()
}
Пример #3
0
func (h *testHarness) saveKeys(ents []*openpgp.Entity, filename string) {
	if h.Err != nil {
		return
	}
	f, err := os.OpenFile(filename, os.O_WRONLY, 0)
	if err != nil {
		h.Err = fmt.Errorf("opening temp file: %s", err)
		return
	}
	defer f.Close()
	armorWriter, err := armor.Encode(f, openpgp.PublicKeyType, map[string]string{})
	if err != nil {
		h.Err = fmt.Errorf("creating ASCII Armor encoder: %s", err)
		return
	}
	defer armorWriter.Close()
	for _, ent := range ents {
		err = ent.SerializePrivate(armorWriter, nil)
		if err != nil {
			h.Err = fmt.Errorf("writing keyring: %s", err)
			return
		}
	}
}