GMime.CryptoContext¶
- Subclasses:
Methods¶
- Inherited:
- Structs:
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Properties¶
None
Signals¶
- Inherited:
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
---|---|---|---|
parent_object |
r |
parent |
|
request_passwd |
r |
a callback for requesting a password |
Class Details¶
- class GMime.CryptoContext(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
A crypto context for use with MIME.
- classmethod new(protocol)¶
- Parameters:
protocol (
str
) – the crypto protocol- Returns:
a newly allocated
GMime.CryptoContext
.- Return type:
Creates a new crypto context for the specified protocol.
- decrypt(flags, session_key, istream, ostream)¶
- Parameters:
flags (
GMime.DecryptFlags
) – a set ofGMime.DecryptFlags
istream (
GMime.Stream
) – input/ciphertext streamostream (
GMime.Stream
) – output/cleartext stream
- Raises:
- Returns:
a
GMime.DecryptResult
on success orNone
on error.- Return type:
Decrypts the ciphertext input stream and writes the resulting cleartext to the output stream.
When non-
None
, session_key should be aNone
-terminated string, such as the one returned byGMime.DecryptResult.get_session_key
() from a previous decryption. If the session_key is not valid, decryption will fail.If the encrypted input stream was also signed, the returned
GMime.DecryptResult
will have a non-None
list of signatures, each with aGMime.SignatureStatus
(among other details about each signature).On success, the returned
GMime.DecryptResult
will contain a list of certificates, one for each recipient, that the original encrypted stream was encrypted to.Note: It *may* be possible to maliciously design an encrypted stream such that recursively decrypting it will result in an endless loop, causing a denial of service attack on your application.
- digest_id(name)¶
- Parameters:
name (
str
) – digest name- Returns:
the equivalent digest id or
GMime.DigestAlgo.DEFAULT
on fail.- Return type:
Gets the digest id based on the digest name.
- digest_name(digest)¶
- Parameters:
digest (
GMime.DigestAlgo
) – digest id- Returns:
the equivalent digest name or
None
on fail.- Return type:
Gets the digest name based on the digest id digest.
- encrypt(sign, userid, flags, recipients, istream, ostream)¶
- Parameters:
sign (
bool
) – sign as well as encryptuserid (
str
orNone
) – the key id (or email address) to use when signing (assuming sign isTrue
)flags (
GMime.EncryptFlags
) – a set ofGMime.EncryptFlags
recipients ([
str
]) – an array of recipient key ids and/or email addressesistream (
GMime.Stream
) – cleartext input streamostream (
GMime.Stream
) – ciphertext output stream
- Raises:
- Returns:
%0 on success or %-1 on fail.
- Return type:
Encrypts (and optionally signs) the cleartext input stream and writes the resulting ciphertext to the output stream.
- export_keys(keys, ostream)¶
- Parameters:
keys ([
str
]) – an array of key ids, terminated by aNone
elementostream (
GMime.Stream
) – output stream
- Raises:
- Returns:
%0 on success or %-1 on fail.
- Return type:
Exports the keys/certificates in keys to the stream ostream from the key/certificate database controlled by self.
If keys is
None
or contains only aNone
element, then all keys will be exported.
- get_encryption_protocol()¶
-
Gets the encryption protocol for the crypto context.
- get_key_exchange_protocol()¶
-
Gets the key exchange protocol for the crypto context.
- get_signature_protocol()¶
-
Gets the signature protocol for the crypto context.
- import_keys(istream)¶
- Parameters:
istream (
GMime.Stream
) – input stream (containing keys)- Raises:
- Returns:
the total number of keys imported on success or %-1 on fail.
- Return type:
Imports a stream of keys/certificates contained within istream into the key/certificate database controlled by self.
- sign(detach, userid, istream, ostream)¶
- Parameters:
detach (
bool
) –True
if ostream should be the detached signature; otherwise,False
userid (
str
) – private key to use to sign the streamistream (
GMime.Stream
) – input streamostream (
GMime.Stream
) – output stream
- Raises:
- Returns:
the
GMime.DigestAlgo
used on success or %-1 on fail.- Return type:
Signs the input stream and writes the resulting signature to the output stream.
- verify(flags, istream, sigstream, ostream)¶
- Parameters:
flags (
GMime.VerifyFlags
) – aGMime.VerifyFlags
istream (
GMime.Stream
) – input streamsigstream (
GMime.Stream
orNone
) – detached-signature streamostream (
GMime.Stream
orNone
) – output stream for use with encapsulated signature input streams
- Raises:
- Returns:
a
GMime.SignatureList
object containing the status of each signature orNone
on error.- Return type:
Verifies the signature. If istream is a clearsigned stream, you should pass
None
as the sigstream parameter and may wish to provide an ostream argument for GMime to output the original plaintext into. Otherwise sigstream is assumed to be the signature stream and is used to verify the integirity of the istream.
- do_decrypt(flags, session_key, istream, ostream) virtual¶
- Parameters:
flags (
GMime.DecryptFlags
) – a set ofGMime.DecryptFlags
istream (
GMime.Stream
) – input/ciphertext streamostream (
GMime.Stream
) – output/cleartext stream
- Returns:
a
GMime.DecryptResult
on success orNone
on error.- Return type:
Decrypts the ciphertext input stream and writes the resulting cleartext to the output stream.
When non-
None
, session_key should be aNone
-terminated string, such as the one returned byGMime.DecryptResult.get_session_key
() from a previous decryption. If the session_key is not valid, decryption will fail.If the encrypted input stream was also signed, the returned
GMime.DecryptResult
will have a non-None
list of signatures, each with aGMime.SignatureStatus
(among other details about each signature).On success, the returned
GMime.DecryptResult
will contain a list of certificates, one for each recipient, that the original encrypted stream was encrypted to.Note: It *may* be possible to maliciously design an encrypted stream such that recursively decrypting it will result in an endless loop, causing a denial of service attack on your application.
- do_digest_id(name) virtual¶
- Parameters:
name (
str
) – digest name- Returns:
the equivalent digest id or
GMime.DigestAlgo.DEFAULT
on fail.- Return type:
Gets the digest id based on the digest name.
- do_digest_name(digest) virtual¶
- Parameters:
digest (
GMime.DigestAlgo
) – digest id- Returns:
the equivalent digest name or
None
on fail.- Return type:
Gets the digest name based on the digest id digest.
- do_encrypt(sign, userid, flags, recipients, istream, ostream) virtual¶
- Parameters:
sign (
bool
) – sign as well as encryptuserid (
str
orNone
) – the key id (or email address) to use when signing (assuming sign isTrue
)flags (
GMime.EncryptFlags
) – a set ofGMime.EncryptFlags
recipients ([
str
]) – an array of recipient key ids and/or email addressesistream (
GMime.Stream
) – cleartext input streamostream (
GMime.Stream
) – ciphertext output stream
- Returns:
%0 on success or %-1 on fail.
- Return type:
Encrypts (and optionally signs) the cleartext input stream and writes the resulting ciphertext to the output stream.
- do_export_keys(keys, ostream) virtual¶
- Parameters:
keys ([
str
]) – an array of key ids, terminated by aNone
elementostream (
GMime.Stream
) – output stream
- Returns:
%0 on success or %-1 on fail.
- Return type:
Exports the keys/certificates in keys to the stream ostream from the key/certificate database controlled by ctx.
If keys is
None
or contains only aNone
element, then all keys will be exported.
- do_get_encryption_protocol() virtual¶
-
Gets the encryption protocol for the crypto context.
- do_get_key_exchange_protocol() virtual¶
-
Gets the key exchange protocol for the crypto context.
- do_get_signature_protocol() virtual¶
-
Gets the signature protocol for the crypto context.
- do_import_keys(istream) virtual¶
- Parameters:
istream (
GMime.Stream
) – input stream (containing keys)- Returns:
the total number of keys imported on success or %-1 on fail.
- Return type:
Imports a stream of keys/certificates contained within istream into the key/certificate database controlled by ctx.
- do_sign(detach, userid, istream, ostream) virtual¶
- Parameters:
detach (
bool
) –True
if ostream should be the detached signature; otherwise,False
userid (
str
) – private key to use to sign the streamistream (
GMime.Stream
) – input streamostream (
GMime.Stream
) – output stream
- Returns:
the
GMime.DigestAlgo
used on success or %-1 on fail.- Return type:
Signs the input stream and writes the resulting signature to the output stream.
- do_verify(flags, istream, sigstream, ostream) virtual¶
- Parameters:
flags (
GMime.VerifyFlags
) – aGMime.VerifyFlags
istream (
GMime.Stream
) – input streamsigstream (
GMime.Stream
orNone
) – detached-signature streamostream (
GMime.Stream
orNone
) – output stream for use with encapsulated signature input streams
- Returns:
a
GMime.SignatureList
object containing the status of each signature orNone
on error.- Return type:
Verifies the signature. If istream is a clearsigned stream, you should pass
None
as the sigstream parameter and may wish to provide an ostream argument for GMime to output the original plaintext into. Otherwise sigstream is assumed to be the signature stream and is used to verify the integirity of the istream.