def test_write_new_specific():
    with open(os.path.join(pytest.test_dir, 'fixtures/test-ec-ecdsa-cert.pem'),
              'rb') as f:
        der_bytes = f.read()
    obj = optiga_objects.X509(0xe0e1)
    old_meta = {'change': obj.meta['change']}
    obj.meta = {'change': 'always'}
    optiga_objects.X509(0xe0e1).der = der_bytes
    obj.meta = old_meta
def test_write_new_default():
    with pytest.raises(IOError):
        with open(
                os.path.join(pytest.test_dir,
                             'fixtures/test-ec-ecdsa-cert.pem'), 'rb') as f:
            der_bytes = f.read()
        optiga_objects.X509(0xe0e0).der = der_bytes
def test_read_existing_multiple_times():
    c = optiga_objects.X509(0xe0e0)
    _ = c.pem
    _ = c.pem
    _ = c.pem
    _ = c.pem
    _ = c.pem
def test_write_new_faulty_objid():
    with pytest.raises(ValueError):
        with open(
                os.path.join(pytest.test_dir,
                             'fixtures/test-ec-ecdsa-cert.pem'), 'rb') as f:
            wr_bytes = f.read()

        optiga_objects.X509(0xe0ec).der = wr_bytes
def test_read_existing_verify_result():
    c = optiga_objects.X509(0xe0e0)

    der_bytes = c.der
    asn1_x509.Certificate.load(der_bytes)

    pem_str = c.pem
    _, _, der_str = asn1_pem.unarmor(pem_str)
    asn1_x509.Certificate.load(der_str)
def test_write_new_locked_object():
    c = optiga_objects.X509(0xe0e1)
    old_meta = c.meta['change']
    with pytest.raises(IOError):
        with open(
                os.path.join(pytest.test_dir,
                             'fixtures/test-ec-ecdsa-cert.pem'), 'rb') as f:
            wr_bytes = f.read()

        c.meta = {"change": "never"}
        c.der = wr_bytes

    c.meta = {'change': old_meta}
def test_meta_read_certificate():
    obj = objects.X509(0xe0e0)
    print(obj.meta)
def test_read_existing():
    c = optiga_objects.X509(0xe0e0)
    assert isinstance(c.der, bytes)
def test_read_existing_faulty_objid():
    with pytest.raises(ValueError):
        optiga_objects.X509(0xe0e7)