add signcryption methods to the keyrings (#109)
* add signcryption methods to the keyrings * added signing and verifying keyrings * added nil checks * added unit test for signcrypt * updated changelog * switched the keyrings in the api * update the error messages * changed the names of the keyRing variable
This commit is contained in:
parent
a42d48a203
commit
e0deea82a3
3 changed files with 64 additions and 1 deletions
|
|
@ -76,7 +76,7 @@ func (keyRing *KeyRing) SignDetached(message *PlainMessage) (*PGPSignature, erro
|
|||
return NewPGPSignature(outBuf.Bytes()), nil
|
||||
}
|
||||
|
||||
// VerifyDetached verifies a PlainMessage with embedded a PGPSignature
|
||||
// VerifyDetached verifies a PlainMessage with a detached PGPSignature
|
||||
// and returns a SignatureVerificationError if fails.
|
||||
func (keyRing *KeyRing) VerifyDetached(message *PlainMessage, signature *PGPSignature, verifyTime int64) error {
|
||||
return verifySignature(
|
||||
|
|
@ -87,6 +87,36 @@ func (keyRing *KeyRing) VerifyDetached(message *PlainMessage, signature *PGPSign
|
|||
)
|
||||
}
|
||||
|
||||
// SignDetachedEncrypted generates and returns a PGPMessage
|
||||
// containing an encrypted detached signature for a given PlainMessage.
|
||||
func (keyRing *KeyRing) SignDetachedEncrypted(message *PlainMessage, encryptionKeyRing *KeyRing) (encryptedSignature *PGPMessage, err error) {
|
||||
if encryptionKeyRing == nil {
|
||||
return nil, errors.New("gopenpgp: no encryption key ring provided")
|
||||
}
|
||||
signature, err := keyRing.SignDetached(message)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
plainMessage := NewPlainMessage(signature.GetBinary())
|
||||
encryptedSignature, err = encryptionKeyRing.Encrypt(plainMessage, nil)
|
||||
return
|
||||
}
|
||||
|
||||
// VerifyDetachedEncrypted verifies a PlainMessage
|
||||
// with a PGPMessage containing an encrypted detached signature
|
||||
// and returns a SignatureVerificationError if fails.
|
||||
func (keyRing *KeyRing) VerifyDetachedEncrypted(message *PlainMessage, encryptedSignature *PGPMessage, decryptionKeyRing *KeyRing, verifyTime int64) error {
|
||||
if decryptionKeyRing == nil {
|
||||
return errors.New("gopenpgp: no decryption key ring provided")
|
||||
}
|
||||
plainMessage, err := decryptionKeyRing.Decrypt(encryptedSignature, nil, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
signature := NewPGPSignature(plainMessage.GetBinary())
|
||||
return keyRing.VerifyDetached(message, signature, verifyTime)
|
||||
}
|
||||
|
||||
// ------ INTERNAL FUNCTIONS -------
|
||||
|
||||
// Core for encryption+signature functions.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue