Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
5.2.3.7. Preferred Symmetric Algorithms
(array of one-octet values)
Symmetric algorithm numbers that indicate which algorithms the key
holder prefers to use. The subpacket body is an ordered list of
octets with the most preferred listed first. It is assumed that only
algorithms listed are supported by the recipient's software.
Algorithm numbers are in Section 9. This is only found on a self-
signature.
"""
__typeid__ = 0x0B
__flags__ = SymmetricKeyAlgorithm
class RevocationKey(Signature):
"""
5.2.3.15. Revocation Key
(1 octet of class, 1 octet of public-key algorithm ID, 20 octets of
fingerprint)
Authorizes the specified key to issue revocation signatures for this
key. Class octet must have bit 0x80 set. If the bit 0x40 is set,
then this means that the revocation information is sensitive. Other
bits are for future expansion to other kinds of authorizations. This
is found on a self-signature.
If the "sensitive" flag is set, the keyholder feels this subpacket
contains private trust information that describes a real-world
sensitive relationship. If this flag is set, implementations SHOULD
NOT export this signature to other users except in cases where the
super(ReasonForRevocation, self).parse(packet)
self.code = packet[:1]
del packet[:1]
self.string = packet[:(self.header.length - 2)]
del packet[:(self.header.length - 2)]
class Features(ByteFlag):
__typeid__ = 0x1E
__flags__ = _Features
##TODO: obtain subpacket type 0x1F - Signature Target
class EmbeddedSignature(Signature):
__typeid__ = 0x20
@sdproperty
def _sig(self):
return self._sigpkt
@_sig.setter
def _sig(self, val):
esh = EmbeddedSignatureHeader()
esh.version = val.header.version
val.header = esh
val.update_hlen()
self._sigpkt = val
@property
def sigtype(self):
def __init__(self):
super(CreationTime, self).__init__()
self.created = datetime.utcnow()
def __bytearray__(self):
_bytes = super(CreationTime, self).__bytearray__()
_bytes += self.int_to_bytes(calendar.timegm(self.created.timetuple()), 4)
return _bytes
def parse(self, packet):
super(CreationTime, self).parse(packet)
self.created = packet[:4]
del packet[:4]
class SignatureExpirationTime(Signature):
"""
5.2.3.10. Signature Expiration Time
(4-octet time field)
The validity period of the signature. This is the number of seconds
after the signature creation time that the signature expires. If
this is not present or has a value of zero, it never expires.
"""
__typeid__ = 0x03
@sdproperty
def expires(self):
return self._expires
@expires.register(timedelta)
def __init__(self):
super(EmbeddedSignature, self).__init__()
from ..packets import SignatureV4
self._sigpkt = SignatureV4()
self._sigpkt.header = EmbeddedSignatureHeader()
def __bytearray__(self):
return super(EmbeddedSignature, self).__bytearray__() + self._sigpkt.__bytearray__()
def parse(self, packet):
super(EmbeddedSignature, self).parse(packet)
self._sig.parse(packet)
class IssuerFingerprint(Signature):
__typeid__ = 0x21
@sdproperty
def version(self):
return self._version
@version.register(int)
def version_int(self, val):
self._version = val
@version.register(bytearray)
def version_bytearray(self, val):
self.version = self.bytes_to_int(val)
@sdproperty
def issuer_fingerprint(self):
def __init__(self):
super(Issuer, self).__init__()
self.issuer = bytearray()
def __bytearray__(self):
_bytes = super(Issuer, self).__bytearray__()
_bytes += binascii.unhexlify(self._issuer.encode())
return _bytes
def parse(self, packet):
super(Issuer, self).parse(packet)
self.issuer = packet[:8]
del packet[:8]
class NotationData(Signature):
__typeid__ = 0x14
@sdproperty
def flags(self):
return self._flags
@flags.register(list)
def flags_list(self, val):
self._flags = val
@flags.register(int)
@flags.register(NotationDataFlags)
def flags_int(self, val):
self.flags += NotationDataFlags & val
@flags.register(bytearray)
'NotationData',
'PreferredHashAlgorithms',
'PreferredCompressionAlgorithms',
'KeyServerPreferences',
'PreferredKeyServer',
'PrimaryUserID',
'Policy',
'KeyFlags',
'SignersUserID',
'ReasonForRevocation',
'Features',
'EmbeddedSignature',
'IssuerFingerprint']
class URI(Signature):
@sdproperty
def uri(self):
return self._uri
@uri.register(str)
@uri.register(six.text_type)
def uri_str(self, val):
self._uri = val
@uri.register(bytearray)
def uri_bytearray(self, val):
self.uri = val.decode('latin-1')
def __init__(self):
super(URI, self).__init__()
self.uri = ""
@abc.abstractmethod
def parse(self, packet): # pragma: no cover
if self.header._typeid == 0:
self.header.parse(packet)
class Signature(SubPacket):
__typeid__ = -1
class UserAttribute(SubPacket):
__typeid__ = -1
class Opaque(Signature, UserAttribute):
__typeid__ = None
@sdproperty
def payload(self):
return self._payload
@payload.register(bytes)
@payload.register(bytearray)
def payload_bin(self, val):
self._payload = bytearray(val)
def __init__(self):
super(Opaque, self).__init__()
self.payload = b''
def __bytearray__(self):
_bytes += self.int_to_bytes(sum(self.keyclass))
_bytes += self.int_to_bytes(self.algorithm.value)
_bytes += self.fingerprint.__bytes__()
return _bytes
def parse(self, packet):
super(RevocationKey, self).parse(packet)
self.keyclass = packet[:1]
del packet[:1]
self.algorithm = packet[:1]
del packet[:1]
self.fingerprint = packet[:20]
del packet[:20]
class Issuer(Signature):
__typeid__ = 0x10
@sdproperty
def issuer(self):
return self._issuer
@issuer.register(bytearray)
def issuer_bytearray(self, val):
self._issuer = binascii.hexlify(val).upper().decode('latin-1')
def __init__(self):
super(Issuer, self).__init__()
self.issuer = bytearray()
def __bytearray__(self):
_bytes = super(Issuer, self).__bytearray__()
class PreferredCompressionAlgorithms(FlagList):
__typeid__ = 0x16
__flags__ = CompressionAlgorithm
class KeyServerPreferences(FlagList):
__typeid__ = 0x17
__flags__ = _KeyServerPreferences
class PreferredKeyServer(URI):
__typeid__ = 0x18
class PrimaryUserID(Signature):
__typeid__ = 0x19
@sdproperty
def primary(self):
return self._primary
@primary.register(bool)
def primary_bool(self, val):
self._primary = val
@primary.register(bytearray)
def primary_byrearray(self, val):
self.primary = bool(self.bytes_to_int(val))
def __init__(self):
super(PrimaryUserID, self).__init__()
The receiver of a transported key "imports" it, and likewise trims
any local certifications. In normal operation, there won't be any,
assuming the import is performed on an exported key. However, there
are instances where this can reasonably happen. For example, if an
implementation allows keys to be imported from a key database in
addition to an exported key, then this situation can arise.
Some implementations do not represent the interest of a single user
(for example, a key server). Such implementations always trim local
certifications from any key they handle.
"""
__typeid__ = 0x04
class TrustSignature(Signature):
"""
5.2.3.13. Trust Signature
(1 octet "level" (depth), 1 octet of trust amount)
Signer asserts that the key is not only valid but also trustworthy at
the specified level. Level 0 has the same meaning as an ordinary
validity signature. Level 1 means that the signed key is asserted to
be a valid trusted introducer, with the 2nd octet of the body
specifying the degree of trust. Level 2 means that the signed key is
asserted to be trusted to issue level 1 trust signatures, i.e., that
it is a "meta introducer". Generally, a level n trust signature
asserts that a key is trusted to issue level n-1 trust signatures.
The trust amount is in a range from 0-255, interpreted such that
values less than 120 indicate partial trust and values of 120 or
greater indicate complete trust. Implementations SHOULD emit values