1 Commits

Author SHA1 Message Date
Morgan
fa7816f358 Resolve date parsing ambiguity when parsing dates when "time/large-dates" feature is enabled
- add explicit delimitter between year and month in date parsing format string
- enable "time/large-dates" feature to dev-dependencies

resolves #34
2024-09-22 19:56:12 +00:00
3 changed files with 21 additions and 46 deletions

View File

@@ -1,33 +0,0 @@
name: Rust
on:
push:
branches: [ "develop", "ci" ]
pull_request:
branches: [ "develop" ]
env:
CARGO_TERM_COLOR: always
jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
rust: [stable]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
default: true
override: true
- name: Format Check
run: cargo fmt --check
- name: Build
run: cargo build
- name: Run tests
run: cargo test

View File

@@ -18,4 +18,4 @@ time = { default-features = false, version = "0.3", features = ["formattin
[dev-dependencies]
quickcheck = "1.0.3"
rand = "0.8.4"
time = { default-features = false, version = "0.3", features = ["formatting", "macros", "parsing", "quickcheck"] }
time = { default-features = false, version = "0.3", features = ["formatting", "large-dates", "macros", "parsing", "quickcheck"] }

View File

@@ -152,34 +152,34 @@ impl ASN1Block {
impl PartialEq for ASN1Block {
fn eq(&self, other: &ASN1Block) -> bool {
match (self, other) {
(&ASN1Block::Boolean(_, a1), &ASN1Block::Boolean(_, a2)) => a1 == a2,
(&ASN1Block::Integer(_, ref a1), &ASN1Block::Integer(_, ref a2)) => a1 == a2,
(&ASN1Block::Boolean(_, a1), &ASN1Block::Boolean(_, a2)) => (a1 == a2),
(&ASN1Block::Integer(_, ref a1), &ASN1Block::Integer(_, ref a2)) => (a1 == a2),
(&ASN1Block::BitString(_, a1, ref b1), &ASN1Block::BitString(_, a2, ref b2)) => {
(a1 == a2) && (b1 == b2)
}
(&ASN1Block::OctetString(_, ref a1), &ASN1Block::OctetString(_, ref a2)) => a1 == a2,
(&ASN1Block::OctetString(_, ref a1), &ASN1Block::OctetString(_, ref a2)) => (a1 == a2),
(&ASN1Block::Null(_), &ASN1Block::Null(_)) => true,
(&ASN1Block::ObjectIdentifier(_, ref a1), &ASN1Block::ObjectIdentifier(_, ref a2)) => {
a1 == a2
}
(&ASN1Block::UTF8String(_, ref a1), &ASN1Block::UTF8String(_, ref a2)) => a1 == a2,
(&ASN1Block::UTF8String(_, ref a1), &ASN1Block::UTF8String(_, ref a2)) => (a1 == a2),
(&ASN1Block::PrintableString(_, ref a1), &ASN1Block::PrintableString(_, ref a2)) => {
a1 == a2
}
(&ASN1Block::TeletexString(_, ref a1), &ASN1Block::TeletexString(_, ref a2)) => {
a1 == a2
}
(&ASN1Block::IA5String(_, ref a1), &ASN1Block::IA5String(_, ref a2)) => a1 == a2,
(&ASN1Block::UTCTime(_, ref a1), &ASN1Block::UTCTime(_, ref a2)) => a1 == a2,
(&ASN1Block::IA5String(_, ref a1), &ASN1Block::IA5String(_, ref a2)) => (a1 == a2),
(&ASN1Block::UTCTime(_, ref a1), &ASN1Block::UTCTime(_, ref a2)) => (a1 == a2),
(&ASN1Block::GeneralizedTime(_, ref a1), &ASN1Block::GeneralizedTime(_, ref a2)) => {
a1 == a2
}
(&ASN1Block::UniversalString(_, ref a1), &ASN1Block::UniversalString(_, ref a2)) => {
a1 == a2
}
(&ASN1Block::BMPString(_, ref a1), &ASN1Block::BMPString(_, ref a2)) => a1 == a2,
(&ASN1Block::Sequence(_, ref a1), &ASN1Block::Sequence(_, ref a2)) => a1 == a2,
(&ASN1Block::Set(_, ref a1), &ASN1Block::Set(_, ref a2)) => a1 == a2,
(&ASN1Block::BMPString(_, ref a1), &ASN1Block::BMPString(_, ref a2)) => (a1 == a2),
(&ASN1Block::Sequence(_, ref a1), &ASN1Block::Sequence(_, ref a2)) => (a1 == a2),
(&ASN1Block::Set(_, ref a1), &ASN1Block::Set(_, ref a2)) => (a1 == a2),
(
&ASN1Block::Explicit(a1, _, ref b1, ref c1),
&ASN1Block::Explicit(a2, _, ref b2, ref c2),
@@ -515,10 +515,14 @@ fn from_der_(i: &[u8], start_offset: usize) -> Result<Vec<ASN1Block>, ASN1Decode
}
};
let v = format!("{}{}", y_prefix, v);
let mut v = format!("{}{}", y_prefix, v);
// add a manual delimitter between known year position and rest of the
// date string to handle ambiguities when "time/large-dates" feature is
// enabled
v.insert(4, ':');
let format = time::format_description::parse(
"[year][month][day][hour repr:24][minute][second]Z",
"[year]:[month][day][hour repr:24][minute][second]Z",
)
.unwrap();
@@ -549,9 +553,13 @@ fn from_der_(i: &[u8], start_offset: usize) -> Result<Vec<ASN1Block>, ASN1Decode
let idx = v.len() - 1;
v.insert(idx, '0');
}
// add a manual delimitter between known year position and rest of the
// date string to handle ambiguities when "time/large-dates" feature is
// enabled
v.insert(4, ':');
let format = time::format_description::parse(
"[year][month][day][hour repr:24][minute][second].[subsecond]Z",
"[year]:[month][day][hour repr:24][minute][second].[subsecond]Z",
)
.unwrap();