| 1 | use oid::prelude::*; |
| 2 | |
| 3 | fn main() -> Result<(), ObjectIdentifierError> { |
| 4 | // define OID as string |
| 5 | let oid_string = "0.1.2.3"; |
| 6 | println!("OID String Test Value: {}", oid_string); |
| 7 | |
| 8 | // parse an OID from a string |
| 9 | let oid = ObjectIdentifier::try_from(oid_string)?; |
| 10 | println!("OID from String: {:#?}", oid); |
| 11 | |
| 12 | // encode the OID back to the same string |
| 13 | let oid_string2: String = (&oid).into(); |
| 14 | assert_eq!(oid_string, oid_string2); |
| 15 | println!("OID String Encoded Value: {}", oid_string2); |
| 16 | |
| 17 | // skip a line on output |
| 18 | println!("\n"); |
| 19 | |
| 20 | // define OID as bytes |
| 21 | let oid_bytes = vec![0x01, 0x02, 0x03]; |
| 22 | println!("OID Binary Test Value: {:?}", oid_bytes); |
| 23 | |
| 24 | // parse an OID from bytes |
| 25 | let oid = ObjectIdentifier::try_from(oid_bytes.clone())?; |
| 26 | println!("OID from Binary: {:#?}", oid); |
| 27 | |
| 28 | // encode the OID back to the same bytes |
| 29 | let oid_bytes2: Vec<u8> = (&oid).into(); |
| 30 | assert_eq!(oid_bytes, oid_bytes2); |
| 31 | println!("OID Binary Encoded Value: {:?}", oid_bytes2); |
| 32 | |
| 33 | Ok(()) |
| 34 | } |