CompressionConfig contains compressor configuration settings.
Level is the compression level to use. It must be set to
between -1 and 9, with -1 causing the compressor to use the
default compression level, 0 causing the compressor to use
no compression and 1 to 9 representing increasing (better,
slower) compression levels. If Level is less than -1 or
more then 9, a non-nil error will be returned during
encryption. See the constants above for convenient common
settings for Level.
func SerializeCompressed(w io.WriteCloser, algo CompressionAlgo, cc *CompressionConfig) (literaldata io.WriteCloser, err error)
EncryptedKey represents a public-key encrypted session key. See RFC 4880,
section 5.1.
AlgoPublicKeyAlgorithm
// only valid after a successful Decrypt
// only valid after a successful Decrypt
KeyIduint64encryptedMPI1parsedMPIencryptedMPI2parsedMPI
Decrypt decrypts an encrypted session key with the given private key. The
private key must have been decrypted first.
If config is nil, sensible defaults will be used.
Serialize writes the encrypted key packet, e, to w.
(*T) parse(r io.Reader) (err error)
*T : Packet
LiteralData represents an encrypted file. See RFC 4880, section 5.9.
Bodyio.ReaderFileNamestringIsBinarybool
// Unix epoch time. Either creation time or modification time. 0 means undefined.
ForEyesOnly returns whether the contents of the LiteralData have been marked
as especially sensitive.
(*T) parse(r io.Reader) (err error)
*T : Packet
OpaquePacket represents an OpenPGP packet as raw, unparsed data. This is
useful for splitting and storing the original packet contents separately,
handling unsupported packet types or accessing parts of the packet not yet
implemented by this package.
Binary contents of the packet data
Reason why the packet was parsed opaquely
Packet type
Parse attempts to parse the opaque contents into a structure supported by
this package. If the packet is not known then the result will be another
OpaquePacket.
Serialize marshals the packet to a writer in its original form, including
the packet header.
(*T) parse(r io.Reader) (err error)
*T : Packet
func (*OpaqueReader).Next() (op *OpaquePacket, err error)
OpaqueReader reads OpaquePackets from an io.Reader.
rio.Reader
Read the next OpaquePacket.
func NewOpaqueReader(r io.Reader) *OpaqueReader
PublicKey represents an OpenPGP public key. See RFC 4880, section 5.5.2.
CreationTimetime.TimeFingerprint[20]byteIsSubkeyboolKeyIduint64PubKeyAlgoPublicKeyAlgorithm
// *rsa.PublicKey, *dsa.PublicKey or *ecdsa.PublicKey
eparsedMPI
RFC 6637 fields
ecdh*ecdhKdfgparsedMPInparsedMPIpparsedMPIqparsedMPIyparsedMPI
BitLength returns the bit length for the given public key.
CanSign returns true iff this public key can generate signatures
KeyIdShortString returns the short form of public key's fingerprint
in capital hex, as shown by gpg --list-keys (e.g. "621CC013").
KeyIdString returns the public key's fingerprint in capital hex
(e.g. "6C7EE1B8621CC013").
(*T) Serialize(w io.Writer) (err error)
SerializeSignaturePrefix writes the prefix for this public key to the given Writer.
The prefix is used when calculating a signature over this public key. See
RFC 4880, section 5.2.4.
VerifyKeySignature returns nil iff sig is a valid signature, made by this
public key, of signed.
VerifyRevocationSignature returns nil iff sig is a valid signature, made by this
public key.
VerifySignature returns nil iff sig is a valid signature, made by this
public key, of the data hashed into signed. signed is mutated by this call.
VerifySignatureV3 returns nil iff sig is a valid signature, made by this
public key, of the data hashed into signed. signed is mutated by this call.
VerifyUserIdSignature returns nil iff sig is a valid signature, made by this
public key, that id is the identity of pub.
VerifyUserIdSignatureV3 returns nil iff sig is a valid signature, made by this
public key, that id is the identity of pub.
(*T) parse(r io.Reader) (err error)
parseDSA parses DSA public key material from the given Reader. See RFC 4880,
section 5.5.2.
parseElGamal parses ElGamal public key material from the given Reader. See
RFC 4880, section 5.5.2.
parseRSA parses RSA public key material from the given Reader. See RFC 4880,
section 5.5.2.
serializeWithoutHeaders marshals the PublicKey to w in the form of an
OpenPGP public key packet, not including the packet header.
(*T) setFingerPrintAndKeyId()
*T : Packet
*T : signingKey
func NewDSAPublicKey(creationTime time.Time, pub *dsa.PublicKey) *PublicKey
func NewECDSAPublicKey(creationTime time.Time, pub *ecdsa.PublicKey) *PublicKey
func NewElGamalPublicKey(creationTime time.Time, pub *elgamal.PublicKey) *PublicKey
func NewRSAPublicKey(creationTime time.Time, pub *rsa.PublicKey) *PublicKey
func SerializeEncryptedKey(w io.Writer, pub *PublicKey, cipherFunc CipherFunction, key []byte, config *Config) error
func (*PublicKey).VerifyKeySignature(signed *PublicKey, sig *Signature) error
func (*PublicKey).VerifyUserIdSignature(id string, pub *PublicKey, sig *Signature) (err error)
func (*PublicKey).VerifyUserIdSignatureV3(id string, pub *PublicKey, sig *SignatureV3) (err error)
func (*Signature).SignKey(pub *PublicKey, priv *PrivateKey, config *Config) error
func (*Signature).SignUserId(id string, pub *PublicKey, priv *PrivateKey, config *Config) error
func userIdSignatureHash(id string, pk *PublicKey, hashFunc crypto.Hash) (h hash.Hash, err error)
func golang.org/x/crypto/openpgp.addSubkey(e *openpgp.Entity, packets *Reader, pub *PublicKey, priv *PrivateKey) error
PublicKeyAlgorithm represents the different public key system specified for
OpenPGP. See
http://www.iana.org/assignments/pgp-parameters/pgp-parameters.xhtml#pgp-parameters-12
CanEncrypt returns true if it's possible to encrypt a message to a public
key of the given type.
CanSign returns true if it's possible for a public key of the given type to
sign a message.
const PubKeyAlgoDSA
const PubKeyAlgoECDH
const PubKeyAlgoECDSA
const PubKeyAlgoElGamal
const PubKeyAlgoRSA
const PubKeyAlgoRSAEncryptOnly
const PubKeyAlgoRSASignOnly
PublicKeyV3 represents older, version 3 public keys. These keys are less secure and
should not be used for signing or encrypting. They are supported here only for
parsing version 3 key material and validating signatures.
See RFC 4880, section 5.5.2.
CreationTimetime.TimeDaysToExpireuint16Fingerprint[16]byteIsSubkeyboolKeyIduint64PubKeyAlgoPublicKeyAlgorithmPublicKey*rsa.PublicKeyeparsedMPInparsedMPI
BitLength returns the bit length for the given public key.
CanSign returns true iff this public key can generate signatures
KeyIdShortString returns the short form of public key's fingerprint
in capital hex, as shown by gpg --list-keys (e.g. "621CC013").
KeyIdString returns the public key's fingerprint in capital hex
(e.g. "6C7EE1B8621CC013").
(*T) Serialize(w io.Writer) (err error)
SerializeSignaturePrefix writes the prefix for this public key to the given Writer.
The prefix is used when calculating a signature over this public key. See
RFC 4880, section 5.2.4.
VerifyKeySignatureV3 returns nil iff sig is a valid signature, made by this
public key, of signed.
VerifySignatureV3 returns nil iff sig is a valid signature, made by this
public key, of the data hashed into signed. signed is mutated by this call.
VerifyUserIdSignatureV3 returns nil iff sig is a valid signature, made by this
public key, that id is the identity of pub.
(*T) parse(r io.Reader) (err error)
parseRSA parses RSA public key material from the given Reader. See RFC 4880,
section 5.5.2.
serializeWithoutHeaders marshals the PublicKey to w in the form of an
OpenPGP public key packet, not including the packet header.
(*T) setFingerPrintAndKeyId()
*T : Packet
*T : signingKey
func newRSAPublicKeyV3(creationTime time.Time, pub *rsa.PublicKey) *PublicKeyV3
func (*PublicKeyV3).VerifyKeySignatureV3(signed *PublicKeyV3, sig *SignatureV3) (err error)
func (*PublicKeyV3).VerifyUserIdSignatureV3(id string, pub *PublicKeyV3, sig *SignatureV3) (err error)
Reader reads packets from an io.Reader and allows packets to be 'unread' so
that they result from the next call to Next.
q[]Packetreaders[]io.Reader
Next returns the most recently unread Packet, or reads another packet from
the top-most io.Reader. Unknown packet types are skipped.
Push causes the Reader to start reading from a new io.Reader. When an EOF
error is seen from the new io.Reader, it is popped and the Reader continues
to read from the next most recent io.Reader. Push returns a StructuralError
if pushing the reader would exceed the maximum recursion level, otherwise it
returns nil.
Unread causes the given Packet to be returned from the next call to Next.
func NewReader(r io.Reader) *Reader
func golang.org/x/crypto/openpgp.ReadEntity(packets *Reader) (*openpgp.Entity, error)
func golang.org/x/crypto/openpgp.addSubkey(e *openpgp.Entity, packets *Reader, pub *PublicKey, priv *PrivateKey) error
func golang.org/x/crypto/openpgp.addUserID(e *openpgp.Entity, packets *Reader, pkt *UserId) error
func golang.org/x/crypto/openpgp.readSignedMessage(packets *Reader, mdin *openpgp.MessageDetails, keyring openpgp.KeyRing) (md *openpgp.MessageDetails, err error)
func golang.org/x/crypto/openpgp.readToNextPublicKey(packets *Reader) (err error)
SymmetricallyEncrypted represents a symmetrically encrypted byte string. The
encrypted contents will consist of more OpenPGP packets. See RFC 4880,
sections 5.7 and 5.13.
// true iff this is a type 18 packet and thus has an embedded MAC.
contentsio.Readerprefix[]byte
Decrypt returns a ReadCloser, from which the decrypted contents of the
packet can be read. An incorrect key can, with high probability, be detected
immediately and this will result in a KeyIncorrect error being returned.
(*T) parse(r io.Reader) error
*T : Packet
SymmetricKeyEncrypted represents a passphrase protected session key. See RFC
4880, section 5.3.
CipherFuncCipherFunctionencryptedKey[]bytes2kfunc(out, in []byte)
Decrypt attempts to decrypt an encrypted session key and returns the key and
the cipher to use when decrypting a subsequent Symmetrically Encrypted Data
packet.
(*T) parse(r io.Reader) error
*T : Packet
UserAttribute is capable of storing other types of data about a user
beyond name, email and a text comment. In practice, user attributes are typically used
to store a signed thumbnail photo JPEG image of the user.
See RFC 4880, section 5.12.
Contents[]*OpaqueSubpacket
ImageData returns zero or more byte slices, each containing
JPEG File Interchange Format (JFIF), for each photo in the
user attribute packet.
Serialize marshals the user attribute to w in the form of an OpenPGP packet, including
header.
(*T) parse(r io.Reader) (err error)
*T : Packet
func NewUserAttribute(contents ...*OpaqueSubpacket) *UserAttribute
func NewUserAttributePhoto(photos ...image.Image) (uat *UserAttribute, err error)
UserId contains text that is intended to represent the name and email
address of the key holder. See RFC 4880, section 5.11. By convention, this
takes the form "Full Name (Comment) <email@example.com>"
CommentstringEmailstring
// By convention, this takes the form "Full Name (Comment) <email@example.com>" which is split out in the fields below.
Namestring
Serialize marshals uid to w in the form of an OpenPGP packet, including
header.
(*T) parse(r io.Reader) (err error)
*T : Packet
func NewUserId(name, comment, email string) *UserId
func golang.org/x/crypto/openpgp.addUserID(e *openpgp.Entity, packets *Reader, pkt *UserId) error
compressedWriterCloser represents the serialized compression stream
header and the compressor. Its Close() method ensures that both the
compressor and serialized stream header are closed. Its Write()
method writes to the compressor.
// Compressor
// Stream Header
( T) Close() (err error)( T) Write(p []byte) (int, error)
T : github.com/go-git/go-git/v5/plumbing/protocol/packp/sideband.Progress
T : github.com/jbenet/go-context/io.Writer
T : io.Closer
T : io.WriteCloser
T : io.Writer
ecdsaKey stores the algorithm-specific fields for ECDSA keys.
as defined in RFC 6637, Section 9.
oid contains the OID byte sequence identifying the elliptic curve used
p contains the elliptic curve point that represents the public key
(*T) byteLen() int(*T) newECDSA() (*ecdsa.PublicKey, error)(*T) parse(r io.Reader) (err error)(*T) serialize(w io.Writer) (err error)
*T : Packet
noOpCloser is like an ioutil.NopCloser, but for an io.Writer.
wio.Writer( T) Close() error( T) Write(data []byte) (n int, err error)
T : github.com/go-git/go-git/v5/plumbing/protocol/packp/sideband.Progress
T : github.com/jbenet/go-context/io.Writer
T : io.Closer
T : io.WriteCloser
T : io.Writer
A parsedMPI is used to store the contents of a big integer, along with the
bit length that was specified in the original input. This allows the MPI to
be reserialized exactly.
bitLengthuint16bytes[]byte
func fromBig(n *big.Int) parsedMPI
func writeMPIs(w io.Writer, mpis ...parsedMPI) (err error)
partialLengthReader wraps an io.Reader and handles OpenPGP partial lengths.
The continuation lengths are parsed and removed from the stream and EOF is
returned at the end of the packet. See RFC 4880, section 4.2.2.4.
isPartialboolrio.Readerremainingint64(*T) Read(p []byte) (n int, err error)
*T : github.com/jbenet/go-context/io.Reader
*T : io.Reader
An seMDCReader wraps an io.Reader, maintains a running hash and keeps hold
of the most recent 22 bytes (mdcTrailerSize). Upon EOF, those bytes form an
MDC packet containing a hash of the previous contents which is checked
against the running hash. See RFC 4880, section 5.13.
eofboolerrorboolhhash.Hashinio.Readerscratch[22]bytetrailer[22]bytetrailerUsedint(*T) Close() error(*T) Read(buf []byte) (n int, err error)
*T : github.com/jbenet/go-context/io.Reader
*T : io.Closer
*T : io.ReadCloser
*T : io.Reader
An seMDCWriter writes through to an io.WriteCloser while maintains a running
hash of the data written. On close, it emits an MDC packet containing the
running hash.
hhash.Hashwio.WriteCloser(*T) Close() (err error)(*T) Write(buf []byte) (n int, err error)
*T : github.com/go-git/go-git/v5/plumbing/protocol/packp/sideband.Progress
*T : github.com/jbenet/go-context/io.Writer
*T : io.Closer
*T : io.WriteCloser
*T : io.Writer
A spanReader is an io.LimitReader, but it returns ErrUnexpectedEOF if the
underlying Reader returns EOF before the limit has been reached.
nint64rio.Reader(*T) Read(p []byte) (n int, err error)
*T : github.com/jbenet/go-context/io.Reader
*T : io.Reader
Package-Level Functions (total 60, in which 23 are exported)
NewElGamalPublicKey returns a PublicKey that wraps the given elgamal.PublicKey.
NewOCFBDecrypter returns a cipher.Stream which decrypts data with OpenPGP's
cipher feedback mode using the given cipher.Block. Prefix must be the first
blockSize + 2 bytes of the ciphertext, where blockSize is the cipher.Block's
block size. If an incorrect key is detected then nil is returned. On
successful exit, blockSize+2 bytes of decrypted data are written into
prefix. Resync determines if the "resynchronization step" from RFC 4880,
13.9 step 7 is performed. Different parts of OpenPGP vary on this point.
NewOCFBEncrypter returns a cipher.Stream which encrypts data with OpenPGP's
cipher feedback mode using the given cipher.Block, and an initial amount of
ciphertext. randData must be random bytes and be the same length as the
cipher.Block's block size. Resync determines if the "resynchronization step"
from RFC 4880, 13.9 step 7 is performed. Different parts of OpenPGP vary on
this point.
NewRSAPublicKey returns a PublicKey that wraps the given rsa.PublicKey.
NewSignerPrivateKey creates a PrivateKey from a crypto.Signer that
implements RSA or ECDSA.
NewUserAttribute creates a new user attribute packet containing the given subpackets.
NewUserAttributePhoto creates a user attribute packet
containing the given images.
NewUserId returns a UserId or nil if any of the arguments contain invalid
characters. The invalid characters are '\x00', '(', ')', '<' and '>'
OpaqueSubpackets extracts opaque, unparsed OpenPGP subpackets from
their byte representation.
Read reads a single OpenPGP packet from the given io.Reader. If there is an
error parsing a packet, the whole packet is consumed from the input.
SerializeCompressed serializes a compressed data packet to w and
returns a WriteCloser to which the literal data packets themselves
can be written and which MUST be closed on completion. If cc is
nil, sensible defaults will be used to configure the compression
algorithm.
SerializeEncryptedKey serializes an encrypted key packet to w that contains
key, encrypted to pub.
If config is nil, sensible defaults will be used.
SerializeLiteral serializes a literal data packet to w and returns a
WriteCloser to which the data itself can be written and which MUST be closed
on completion. The fileName is truncated to 255 bytes.
SerializeSymmetricallyEncrypted serializes a symmetrically encrypted packet
to w and returns a WriteCloser to which the to-be-encrypted packets can be
written.
If config is nil, sensible defaults will be used.
SerializeSymmetricKeyEncrypted serializes a symmetric key packet to w. The
packet contains a random session key, encrypted by a key derived from the
given passphrase. The session key is returned and must be passed to
SerializeSymmetricallyEncrypted.
If config is nil, sensible defaults will be used.
newRSAPublicKeyV3 returns a PublicKey that wraps the given rsa.PublicKey.
Included here for testing purposes only. RFC 4880, section 5.5.2:
"an implementation MUST NOT generate a V3 key, but MAY accept it."
padToKeySize left-pads a MPI with zeroes to match the length of the
specified RSA public.
parseOID reads the OID for the curve as defined in RFC 6637, Section 9.
parseSignatureSubpacket parses a single subpacket. len(subpacket) is >= 1.
parseSignatureSubpackets parses subpackets of the main signature packet. See
RFC 4880, section 5.2.3.1.
parseUserId extracts the name, comment and email from a user id string that
is formatted as "Full Name (Comment) <email@example.com>".
peekVersion detects the version of a public key packet about to
be read. A bufio.Reader at the original position of the io.Reader
is returned.
readFull is the same as io.ReadFull except that reading zero bytes returns
ErrUnexpectedEOF rather than EOF.
readHeader parses a packet header and returns an io.Reader which will return
the contents of the packet. See RFC 4880, section 4.2.
readLength reads an OpenPGP length from r. See RFC 4880, section 4.2.2.
readMPI reads a big integer from r. The bit length returned is the bit
length that was specified in r. This is preserved so that the integer can be
reserialized exactly.
serializeStreamHeader writes an OpenPGP packet header to w where the
length of the packet is unknown. It returns a io.WriteCloser which can be
used to write the contents of the packet. See RFC 4880, section 4.2.
serializeSubpacketLength marshals the given length into to.
serializeSubpackets marshals the given subpackets into to.
subpacketLengthLength returns the length, in bytes, of an encoded length value.
subpacketsLength returns the serialized length, in bytes, of the given
subpackets.
unwrapECDSASig parses the two integer components of an ASN.1-encoded ECDSA
signature.
userIdSignatureHash returns a Hash of the message that needs to be signed
to assert that pk is a valid key for id.
userIdSignatureV3Hash returns a Hash of the message that needs to be signed
to assert that pk is a valid key for id.
writeBig serializes a *big.Int to w.
writeMPI serializes a big integer to w.
writeMPIs is a utility function for serializing several big integers to the
given Writer.
Package-Level Variables (total 3, none are exported)
NIST curve P-256
NIST curve P-384
NIST curve P-521
Package-Level Constants (total 73, in which 37 are exported)
New io.Readers are pushed when a compressed or encrypted packet is processed
and recursively treated as a new source of packets. However, a carefully
crafted packet can trigger an infinite recursive sequence of packets. See
http://mumble.net/~campbell/misc/pgp-quine
https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2013-4402
This constant limits the number of recursive packets that may be pushed.
This is the largest session key that we'll support. Since no 512-bit cipher
has even been seriously used, this is comfortably large.
This is a new-format packet tag byte for a type 19 (MDC) packet.
The pages are generated with Goldsv0.3.2-preview. (GOOS=darwin GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.