Add algos.KeyExchangeAlgorithm,/lgos.DHParameters, DH key support to keys.PublicKeyAlgorithm
diff --git a/asn1crypto/algos.py b/asn1crypto/algos.py
index 9692d26..fbf26ce 100644
--- a/asn1crypto/algos.py
+++ b/asn1crypto/algos.py
@@ -336,6 +336,36 @@
}
+class DHParameters(Sequence):
+ """
+ Original Name: DHParameter
+ Source: ftp://ftp.rsasecurity.com/pub/pkcs/ascii/pkcs-3.asc section 9
+ """
+
+ _fields = [
+ ('p', Integer),
+ ('g', Integer),
+ ('private_value_length', Integer, {'optional': True}),
+ ]
+
+
+class KeyExchangeAlgorithmId(ObjectIdentifier):
+ _map = {
+ '1.2.840.113549.1.3.1': 'dh',
+ }
+
+
+class KeyExchangeAlgorithm(Sequence):
+ _fields = [
+ ('algorithm', KeyExchangeAlgorithmId),
+ ('parameters', Any, {'optional': True}),
+ ]
+ _oid_pair = ('algorithm', 'parameters')
+ _oid_specs = {
+ 'dh': DHParameters,
+ }
+
+
class Rc2Params(Sequence):
_fields = [
('rc2_parameter_version', Integer, {'optional': True}),
diff --git a/asn1crypto/keys.py b/asn1crypto/keys.py
index 2f79fad..5dad1fc 100644
--- a/asn1crypto/keys.py
+++ b/asn1crypto/keys.py
@@ -34,6 +34,7 @@
from .core import (
Any,
Asn1Value,
+ BitString,
Choice,
Integer,
IntegerOctetString,
@@ -876,6 +877,31 @@
# These structures are from https://tools.ietf.org/html/rfc3279
+class ValidationParms(Sequence):
+ """
+ Source: https://tools.ietf.org/html/rfc3279#page-10
+ """
+
+ _fields = [
+ ('seed', BitString),
+ ('pgen_counter', Integer),
+ ]
+
+
+class DomainParameters(Sequence):
+ """
+ Source: https://tools.ietf.org/html/rfc3279#page-10
+ """
+
+ _fields = [
+ ('p', Integer),
+ ('g', Integer),
+ ('q', Integer),
+ ('j', Integer, {'optional': True}),
+ ('validation_params', ValidationParms, {'optional': True}),
+ ]
+
+
class PublicKeyAlgorithmId(ObjectIdentifier):
"""
Original Name: None
@@ -889,6 +915,8 @@
'1.2.840.10040.4.1': 'dsa',
# https://tools.ietf.org/html/rfc3279#page-13
'1.2.840.10045.2.1': 'ec',
+ # https://tools.ietf.org/html/rfc3279#page-10
+ '1.2.840.10046.2.1': 'dh',
}
@@ -908,6 +936,7 @@
'rsa': Null,
'dsa': DSAParams,
'ec': ECDomainParameters,
+ 'dh': DomainParameters,
}
@@ -930,6 +959,7 @@
# We override the field spec with ECPoint so that users can easily
# decompose the byte string into the constituent X and Y coords
'ec': (ECPointBitString, None),
+ 'dh': Integer,
}[algorithm]
_spec_callbacks = {