|
| 1 | +use criterion::{criterion_group, criterion_main, Criterion}; |
| 2 | +use rasn::prelude::*; |
| 3 | +use rasn_ieee1609dot2::base_types::*; |
| 4 | +use rasn_ieee1609dot2::*; |
| 5 | + |
| 6 | +pub fn build_sample() -> Ieee1609Dot2Data { |
| 7 | + Ieee1609Dot2Data::builder() |
| 8 | + .protocol_version(3) |
| 9 | + .content(Ieee1609Dot2Content::SignedData(Box::new( |
| 10 | + SignedData::builder() |
| 11 | + .hash_id(HashAlgorithm::Sha256) |
| 12 | + .tbs_data( |
| 13 | + ToBeSignedData::builder() |
| 14 | + .payload( |
| 15 | + SignedDataPayload::builder() |
| 16 | + .data( |
| 17 | + Ieee1609Dot2Data::builder() |
| 18 | + .protocol_version(3) |
| 19 | + .content(Ieee1609Dot2Content::UnsecuredData(Opaque( |
| 20 | + "This is a BSM\r\n".as_bytes().into(), |
| 21 | + ))) |
| 22 | + .build(), |
| 23 | + ) |
| 24 | + .build() |
| 25 | + .unwrap(), |
| 26 | + ) |
| 27 | + .header_info( |
| 28 | + HeaderInfo::builder() |
| 29 | + .psid(Integer::from(32).into()) |
| 30 | + .generation_time(1_230_066_625_199_609_624.into()) |
| 31 | + .build(), |
| 32 | + ) |
| 33 | + .build(), |
| 34 | + ) |
| 35 | + .signer(SignerIdentifier::Certificate( |
| 36 | + vec![Certificate::from(ImplicitCertificate::from( |
| 37 | + CertificateBase::builder() |
| 38 | + .version(3) |
| 39 | + .c_type(CertificateType::Implicit) |
| 40 | + .issuer(IssuerIdentifier::Sha256AndDigest(HashedId8( |
| 41 | + "!\"#$%&'(".as_bytes().try_into().unwrap(), |
| 42 | + ))) |
| 43 | + .to_be_signed( |
| 44 | + ToBeSignedCertificate::builder() |
| 45 | + .id(CertificateId::LinkageData( |
| 46 | + LinkageData::builder() |
| 47 | + .i_cert(IValue::from(100)) |
| 48 | + .linkage_value(LinkageValue( |
| 49 | + FixedOctetString::try_from(b"123456789".as_slice()) |
| 50 | + .unwrap(), |
| 51 | + )) |
| 52 | + .group_linkage_value( |
| 53 | + GroupLinkageValue::builder() |
| 54 | + .j_value(b"ABCD".as_slice().try_into().unwrap()) |
| 55 | + .value( |
| 56 | + b"QRSTUVWXY".as_slice().try_into().unwrap(), |
| 57 | + ) |
| 58 | + .build(), |
| 59 | + ) |
| 60 | + .build(), |
| 61 | + )) |
| 62 | + .craca_id(HashedId3(b"abc".as_slice().try_into().unwrap())) |
| 63 | + .crl_series(CrlSeries::from(70)) |
| 64 | + .validity_period( |
| 65 | + ValidityPeriod::builder() |
| 66 | + .start(81_828_384.into()) |
| 67 | + .duration(Duration::Hours(169)) |
| 68 | + .build(), |
| 69 | + ) |
| 70 | + .region(GeographicRegion::IdentifiedRegion( |
| 71 | + vec![ |
| 72 | + IdentifiedRegion::CountryOnly(UnCountryId::from(124)), |
| 73 | + IdentifiedRegion::CountryOnly(UnCountryId::from(484)), |
| 74 | + IdentifiedRegion::CountryOnly(UnCountryId::from(840)), |
| 75 | + ] |
| 76 | + .into(), |
| 77 | + )) |
| 78 | + .app_permissions( |
| 79 | + vec![ |
| 80 | + PsidSsp { |
| 81 | + psid: Integer::from(32).into(), |
| 82 | + ssp: None, |
| 83 | + }, |
| 84 | + PsidSsp { |
| 85 | + psid: Integer::from(38).into(), |
| 86 | + ssp: None, |
| 87 | + }, |
| 88 | + ] |
| 89 | + .into(), |
| 90 | + ) |
| 91 | + .verify_key_indicator( |
| 92 | + VerificationKeyIndicator::ReconstructionValue( |
| 93 | + EccP256CurvePoint::CompressedY0( |
| 94 | + FixedOctetString::from([ |
| 95 | + 0x91u8, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, |
| 96 | + 0x98, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, |
| 97 | + 0x98, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, |
| 98 | + 0x98, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, |
| 99 | + 0x98, |
| 100 | + ]), |
| 101 | + ), |
| 102 | + ), |
| 103 | + ) |
| 104 | + .build() |
| 105 | + .unwrap(), |
| 106 | + ) |
| 107 | + .build(), |
| 108 | + ))] |
| 109 | + .into(), |
| 110 | + )) |
| 111 | + .signature(Signature::EcdsaNistP256( |
| 112 | + EcdsaP256Signature::builder() |
| 113 | + .r_sig(EccP256CurvePoint::CompressedY0( |
| 114 | + b"12345678123456781234567812345678" |
| 115 | + .as_slice() |
| 116 | + .try_into() |
| 117 | + .unwrap(), |
| 118 | + )) |
| 119 | + .s_sig( |
| 120 | + b"ABCDEFGHABCDEFGHABCDEFGHABCDEFGH" |
| 121 | + .as_slice() |
| 122 | + .try_into() |
| 123 | + .unwrap(), |
| 124 | + ) |
| 125 | + .build(), |
| 126 | + )) |
| 127 | + .build(), |
| 128 | + ))) |
| 129 | + .build() |
| 130 | +} |
| 131 | + |
| 132 | +fn oer_enc_dec(c: &mut Criterion) { |
| 133 | + let cert = build_sample(); |
| 134 | + let mut buffer = Vec::<u8>::with_capacity(core::mem::size_of::<Ieee1609Dot2Data>()); |
| 135 | + |
| 136 | + c.bench_function( |
| 137 | + "RASN/ encode/decode OER ieee1609dot2 - bsm with certificate", |
| 138 | + |b| { |
| 139 | + b.iter(|| { |
| 140 | + // for _ in 0..10_000 { |
| 141 | + rasn::coer::encode_buf(&cert, &mut buffer).unwrap(); |
| 142 | + rasn::coer::decode::<Ieee1609Dot2Data>(&buffer).unwrap(); |
| 143 | + buffer.clear(); |
| 144 | + // } |
| 145 | + }) |
| 146 | + }, |
| 147 | + ); |
| 148 | +} |
| 149 | + |
| 150 | +criterion_group!(benches, oer_enc_dec); |
| 151 | +criterion_main!(benches); |
0 commit comments