Add API to sign stream with context
This commit is contained in:
parent
45070ef1ae
commit
c55b9d203c
4 changed files with 54 additions and 38 deletions
|
|
@ -280,3 +280,36 @@ func verifySignature(
|
|||
|
||||
return sig, nil
|
||||
}
|
||||
|
||||
func signMessageDetached(
|
||||
signKeyRing *KeyRing,
|
||||
messageReader io.Reader,
|
||||
isBinary bool,
|
||||
context *SigningContext,
|
||||
) (*PGPSignature, error) {
|
||||
config := &packet.Config{
|
||||
DefaultHash: crypto.SHA512,
|
||||
Time: getTimeGenerator(),
|
||||
}
|
||||
|
||||
signEntity, err := signKeyRing.getSigningEntity()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if context != nil {
|
||||
config.SignatureNotations = append(config.SignatureNotations, context.getNotation())
|
||||
}
|
||||
|
||||
var outBuf bytes.Buffer
|
||||
if isBinary {
|
||||
err = openpgp.DetachSign(&outBuf, signEntity, messageReader, config)
|
||||
} else {
|
||||
err = openpgp.DetachSignText(&outBuf, signEntity, messageReader, config)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "gopenpgp: error in signing")
|
||||
}
|
||||
|
||||
return NewPGPSignature(outBuf.Bytes()), nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue