| 1 | use oidrust-analyzer cargo oid 0.2.1 crate/::preluderust-analyzer cargo oid 0.2.1 prelude/::*; |
| 2 | |
| 3 | fn mainrust-analyzer cargo oid 0.2.1 main().() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), ObjectIdentifierErrorrust-analyzer cargo oid 0.2.1 ObjectIdentifierError#> { |
| 4 | // define OID as string |
| 5 | let oid_string = "0.1.2.3"; |
| 6 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("OID String Test Value: {}", oid_string); |
| 7 | |
| 8 | // parse an OID from a string |
| 9 | let oid = ObjectIdentifierrust-analyzer cargo oid 0.2.1 ObjectIdentifier#::try_fromrust-analyzer cargo oid 0.2.1 impl#[ObjectIdentifier][`TryFrom<&str>`]try_from().(oid_string)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 10 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("OID from String: {:#?}", oid); |
| 11 | |
| 12 | // encode the OID back to the same string |
| 13 | let oid_string2: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# = (&oid).intorust-analyzer cargo oid 0.2.1 impl#[`&ObjectIdentifier`][`Into<String>`]into().(); |
| 14 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(oid_string, oid_string2); |
| 15 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("OID String Encoded Value: {}", oid_string2); |
| 16 | |
| 17 | // skip a line on output |
| 18 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("\n"); |
| 19 | |
| 20 | // define OID as bytes |
| 21 | let oid_bytes = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0x01, 0x02, 0x03]; |
| 22 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("OID Binary Test Value: {:?}", oid_bytes); |
| 23 | |
| 24 | // parse an OID from bytes |
| 25 | let oid = ObjectIdentifierrust-analyzer cargo oid 0.2.1 ObjectIdentifier#::try_fromrust-analyzer cargo oid 0.2.1 impl#[ObjectIdentifier][`TryFrom<Vec<u8>>`]try_from().(oid_bytes.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Clone]clone().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 26 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("OID from Binary: {:#?}", oid); |
| 27 | |
| 28 | // encode the OID back to the same bytes |
| 29 | let oid_bytes2: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> = (&oid).intorust-analyzer cargo oid 0.2.1 impl#[`&ObjectIdentifier`][`Into<Vec<u8>>`]into().(); |
| 30 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(oid_bytes, oid_bytes2); |
| 31 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("OID Binary Encoded Value: {:?}", oid_bytes2); |
| 32 | |
| 33 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 34 | } |