aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2014-11-27 10:29:59 -1000
committerPaul Kehrer <paul.l.kehrer@gmail.com>2014-11-27 10:29:59 -1000
commit65d054d1a9b8b122096d7994fc2fe675c06f423f (patch)
tree4d42a91fc6a2a9105f04aa11501adec3999af039 /src
parenta98f95a14ef6394795b9a34402d41552e43a8101 (diff)
downloadcryptography-65d054d1a9b8b122096d7994fc2fe675c06f423f.tar.gz
cryptography-65d054d1a9b8b122096d7994fc2fe675c06f423f.tar.bz2
cryptography-65d054d1a9b8b122096d7994fc2fe675c06f423f.zip
add decode_rfc6979_signature helper for DSA/ECDSA
Diffstat (limited to 'src')
-rw-r--r--src/cryptography/hazmat/primitives/asymmetric/utils.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/cryptography/hazmat/primitives/asymmetric/utils.py b/src/cryptography/hazmat/primitives/asymmetric/utils.py
new file mode 100644
index 00000000..5e35b3f6
--- /dev/null
+++ b/src/cryptography/hazmat/primitives/asymmetric/utils.py
@@ -0,0 +1,22 @@
+# This file is dual licensed under the terms of the Apache License, Version
+# 2.0, and the BSD License. See the LICENSE file in the root of this repository
+# for complete details.
+
+from __future__ import absolute_import, division, print_function
+
+from pyasn1.codec.der import decoder
+from pyasn1.type import namedtype, univ
+
+
+class _DSSSigValue(univ.Sequence):
+ componentType = namedtype.NamedTypes(
+ namedtype.NamedType('r', univ.Integer()),
+ namedtype.NamedType('s', univ.Integer())
+ )
+
+
+def decode_rfc6979_signature(signature):
+ data = decoder.decode(signature, asn1Spec=_DSSSigValue())
+ r = int(data[0].getComponentByName('r'))
+ s = int(data[0].getComponentByName('s'))
+ return (r, s)