|
6 | 6 | The following example requires `pip3 install pycryptodome` and uses ecdsa.py in
|
7 | 7 | the same directory as this file.
|
8 | 8 |
|
9 |
| ->>> import binascii, os, sys, textwrap |
| 9 | +>>> import os, sys |
10 | 10 | >>> from pprint import pprint
|
11 | 11 | >>> sys.path.insert(0, os.path.dirname(__file__))
|
12 | 12 | >>> import ecdsa
|
|
26 | 26 | >>> pprint(json.loads(signature_json))
|
27 | 27 | {'payload': 'aGVsbG8gd29ybGQ=',
|
28 | 28 | 'payloadType': 'http://example.com/HelloWorld',
|
29 |
| - 'signatures': [{'sig': 'Cc3RkvYsLhlaFVd+d6FPx4ZClhqW4ZT0rnCYAfv6/ckoGdwT7g/blWNpOBuL/tZhRiVFaglOGTU8GEjm4aEaNA=='}]} |
| 29 | + 'signatures': [{'sig': 'A3JqsQGtVsJ2O2xqrI5IcnXip5GToJ3F+FnZ+O88SjtR6rDAajabZKciJTfUiHqJPcIAriEGAHTVeCUjW2JIZA=='}]} |
30 | 30 |
|
31 | 31 | Verification example:
|
32 | 32 |
|
|
36 | 36 |
|
37 | 37 | PAE:
|
38 | 38 |
|
39 |
| ->>> def print_hex(b: bytes): |
40 |
| -... octets = ' '.join(textwrap.wrap(binascii.hexlify(b).decode('utf-8'), 2)) |
41 |
| -... print(*textwrap.wrap(octets, 48), sep='\n') |
42 |
| ->>> print_hex(PAE(payloadType, payload)) |
43 |
| -02 00 00 00 00 00 00 00 1d 00 00 00 00 00 00 00 |
44 |
| -68 74 74 70 3a 2f 2f 65 78 61 6d 70 6c 65 2e 63 |
45 |
| -6f 6d 2f 48 65 6c 6c 6f 57 6f 72 6c 64 0b 00 00 |
46 |
| -00 00 00 00 00 68 65 6c 6c 6f 20 77 6f 72 6c 64 |
| 39 | +>>> PAE(payloadType, payload) |
| 40 | +b'DSSEv1 29 http://example.com/HelloWorld 11 hello world' |
47 | 41 | """
|
48 | 42 |
|
49 | 43 | import base64, binascii, dataclasses, json, struct
|
@@ -88,12 +82,9 @@ def b64dec(m: str) -> bytes:
|
88 | 82 |
|
89 | 83 |
|
90 | 84 | def PAE(payloadType: str, payload: bytes) -> bytes:
|
91 |
| - return b''.join([ |
92 |
| - struct.pack('<Q', 2), |
93 |
| - struct.pack('<Q', len(payloadType)), |
94 |
| - payloadType.encode('utf-8'), |
95 |
| - struct.pack('<Q', len(payload)), payload |
96 |
| - ]) |
| 85 | + return b'DSSEv1 %d %b %d %b' % ( |
| 86 | + len(payloadType), payloadType.encode('utf-8'), |
| 87 | + len(payload), payload) |
97 | 88 |
|
98 | 89 |
|
99 | 90 | def Sign(payloadType: str, payload: bytes, signer: Signer) -> str:
|
|
0 commit comments