def get_ber_encoded_signed_attributes(signed_attrs): """Get the BER-encoded signed attributes. class_, method, and tag are needed to emit the BER encoded version of the header + content. These values are not exposed on SignerInfo so we get them from the parent class. Args: signed_attrs (asn1crypto.cms.CMSAttributes): The signed attributes from the signature Returns: str: The BER-encoded signed attributes as a string of bytes """ class_ = super(signed_attrs.__class__, signed_attrs).class_ method = super(signed_attrs.__class__, signed_attrs).method tag = super(signed_attrs.__class__, signed_attrs).tag return parser.emit(class_, method, tag, signed_attrs.contents)
def test_emit_type_errors(self): with self.assertRaises(TypeError): parser.emit('0', 0, 2, b'\x00') with self.assertRaises(ValueError): parser.emit(-1, 0, 2, b'\x00') with self.assertRaises(TypeError): parser.emit(0, '0', 2, b'\x00') with self.assertRaises(ValueError): parser.emit(0, 5, 2, b'\x00') with self.assertRaises(TypeError): parser.emit(0, 0, '2', b'\x00') with self.assertRaises(ValueError): parser.emit(0, 0, -1, b'\x00') with self.assertRaises(TypeError): parser.emit(0, 0, 2, '\x00')
def test_emit(self): self.assertEqual(b'\x02\x01\x00', parser.emit(0, 0, 2, b'\x00'))