Пример #1
0
 def test_simple(self, value: Any, number: Optional[asn1.TNumber]) -> None:
     encoder = Encoder()
     encoder.write(value, number)
     data = encoder.output()
     decoder = Decoder(data)
     _, decoded = decoder.read()
     assert decoded == value
     assert decoder.eof()
Пример #2
0
 def test_one_enter(self, number: asn1.TNumber, typ: asn1.TType, values: Tuple, expected: bytes) -> None:
     encoder = Encoder()
     encoder.enter(number, typ)
     for value in values:
         encoder.write(value)
     encoder.exit()
     res = encoder.output()
     assert res == expected
Пример #3
0
    def test_multiple_enter(
        self, values: Tuple[Tuple[asn1.TNumber, Optional[asn1.TClass], Tuple]], expected: bytes
    ) -> None:
        encoder = Encoder()
        for number, typ, values_ in values:
            encoder.enter(number, typ)
            for value in values_:
                encoder.write(value)
            encoder.exit()

        res = encoder.output()
        assert res == expected
Пример #4
0
 def test_simple_encode(self, value: Any, number: Optional[asn1.TNumber], expected: bytes) -> None:
     encoder = Encoder()
     encoder.write(value, number)
     result = encoder.output()
     assert result == expected
Пример #5
0
 def test_invalid_number(self) -> None:
     encoder = Encoder()
     with pytest.raises(Error, match="Unhandled Number 155 value 1"):
         encoder.write(1, 155)
Пример #6
0
 def test_cannot_determine_number(self) -> None:
     encoder = Encoder()
     with pytest.raises(Error, match="Cannot determine Number for value type"):
         encoder.write(1.21)
Пример #7
0
 def test_error_object_identifier(self, value: str) -> None:
     encoder = Encoder()
     with pytest.raises(Error, match="Illegal object identifier"):
         encoder.write(value, asn1.Number.ObjectIdentifier)