1# This file is dual licensed under the terms of the Apache License, Version 2# 2.0, and the BSD License. See the LICENSE file in the root of this repository 3# for complete details. 4 5from __future__ import absolute_import, division, print_function 6 7import pytest 8 9from cryptography.hazmat._oid import ObjectIdentifier 10 11 12def test_basic_oid(): 13 assert ObjectIdentifier("1.2.3.4").dotted_string == "1.2.3.4" 14 15 16def test_oid_constraint(): 17 # Too short 18 with pytest.raises(ValueError): 19 ObjectIdentifier("1") 20 21 # First node too big 22 with pytest.raises(ValueError): 23 ObjectIdentifier("3.2.1") 24 25 # Outside range 26 with pytest.raises(ValueError): 27 ObjectIdentifier("1.40") 28 with pytest.raises(ValueError): 29 ObjectIdentifier("0.42") 30 31 # non-decimal oid 32 with pytest.raises(ValueError): 33 ObjectIdentifier("1.2.foo.bar") 34 with pytest.raises(ValueError): 35 ObjectIdentifier("1.2.0xf00.0xba4") 36 37 # negative oid 38 with pytest.raises(ValueError): 39 ObjectIdentifier("1.2.-3.-4") 40