def make_timestamp_request(data=None, digest=None, hashname='sha1', include_tsa_certificate=False, nonce=None): algorithm_identifier = rfc2459.AlgorithmIdentifier() algorithm_identifier.setComponentByPosition(0, get_hash_oid(hashname)) message_imprint = rfc3161ng.MessageImprint() message_imprint.setComponentByPosition(0, algorithm_identifier) hashobj = hashlib.new(hashname) if digest: assert len( digest ) == hashobj.digest_size, 'digest length is wrong %s != %s' % ( len(digest), hashobj.digest_size) elif data: digest = data_to_digest(data) else: raise ValueError('You must pass some data to digest, or the digest') message_imprint.setComponentByPosition(1, digest) request = rfc3161ng.TimeStampReq() request.setComponentByPosition(0, 'v1') request.setComponentByPosition(1, message_imprint) if nonce is not None: request.setComponentByPosition(3, int(nonce)) request.setComponentByPosition(4, include_tsa_certificate) return request
def decode_timestamp_request(request): tsq, substrate = decoder.decode(request, asn1Spec=rfc3161ng.TimeStampReq()) if substrate: raise ValueError('Extra data returned') return tsq