10 from __future__
import division, absolute_import, print_function, unicode_literals
25 This class implements the UAVCAN DSDL signature hash function. Please refer to the specification for details.
27 MASK64 = 0xFFFFFFFFFFFFFFFF
28 POLY = 0x42F0E1EBA9EA3693
32 extend_from Initial value (optional)
34 if extend_from
is not None:
35 self.
_crc = (
int(extend_from) & Signature.MASK64) ^ Signature.MASK64
37 self.
_crc = Signature.MASK64
39 def add(self, data_bytes):
40 '''Feed ASCII string or bytes to the signature function'''
42 if isinstance(data_bytes, basestring):
43 data_bytes = map(ord, data_bytes)
45 if isinstance(data_bytes, str):
46 data_bytes = map(ord, data_bytes)
49 self.
_crc ^= (b << 56) & Signature.MASK64
51 if self.
_crc & (1 << 63):
52 self.
_crc = ((self.
_crc << 1) & Signature.MASK64) ^ Signature.POLY
57 '''Returns integer signature value'''
58 return (self.
_crc & Signature.MASK64) ^ Signature.MASK64
63 One-shot signature computation for ASCII string or bytes.
64 Returns integer signture value.
76 assert s.get_value() == 0x62EC59E3F1A4F00A