Skip to content

Commit a9180be

Browse files
authored
Merge pull request #11 from KeetaPay/release/v1.1.6
Release: v1.1.6
2 parents 623c8ef + 1112920 commit a9180be

File tree

6 files changed

+34
-27
lines changed

6 files changed

+34
-27
lines changed

.cargo-husky/hooks/pre-commit

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
set -e
33

44
yarn lint-staged
55
cargo fmt
66
cargo clippy --fix --allow-staged
7-
cargo doc --no-deps
7+
cargo doc --no-deps

.cargo-husky/hooks/pre-push

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
set -e
33

44
cargo test --all
55
yarn build
6-
yarn test
6+
yarn test

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
authors = ["Tanveer Wahid <twahid@keeta.com>"]
33
edition = "2021"
44
name = "asn1-napi-rs"
5-
version = "1.1.5"
5+
version = "1.1.6"
66

77
[lib]
88
crate-type = ["cdylib"]
99

1010
[dependencies]
1111
napi = {version = "2.12.6", features = ["chrono_date", "error_anyhow", "napi7"] }
1212
phf = { version = "0.11.1", features = ["macros"] }
13-
napi-derive = "2.11.0"
14-
rasn = "0.6.1"
13+
napi-derive = "2.12.5"
14+
rasn = "0.7.0"
1515
num-bigint = "0.4.3"
16-
chrono = "0.4.22"
16+
chrono = "0.4.24"
1717
base64 = "0.13.0"
1818
hex = "0.4.3"
19-
anyhow = "1.0.65"
20-
thiserror = "1.0.37"
19+
anyhow = "1.0.71"
20+
thiserror = "1.0.40"
2121

2222
[dev-dependencies.cargo-husky]
2323
version = "1.5.0"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@keetapay/asn1-napi-rs",
3-
"version": "1.1.5",
3+
"version": "1.1.6",
44
"homepage": "https://github.com/KeetaPay/asn1-napi-rs#readme",
55
"author": "Tanveer Wahid <twahid@keeta.com>",
66
"description": "KeetaPay ASN.1 TypeScript-Rust NAPI library",

src/asn1.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ mod test {
429429
ASN1Data::Integer(456),
430430
ASN1Data::Integer(123),
431431
ASN1Data::Date(DateTime::<FixedOffset>::from(
432-
Utc.ymd(2022, 6, 22).and_hms_milli(18, 18, 0, 210),
432+
Utc.timestamp_millis_opt(1655921880210).unwrap(),
433433
)),
434434
ASN1Data::Bytes(
435435
hex::decode(
@@ -493,10 +493,10 @@ mod test {
493493
]),
494494
ASN1Data::Array(vec![
495495
ASN1Data::Date(DateTime::<FixedOffset>::from(
496-
Utc.ymd(2022, 11, 03).and_hms_milli(1, 29, 58, 0),
496+
Utc.with_ymd_and_hms(2022, 11, 03, 1, 29, 58).unwrap(),
497497
)),
498498
ASN1Data::Date(DateTime::<FixedOffset>::from(
499-
Utc.ymd(2027, 05, 11).and_hms_milli(1, 29, 58, 0),
499+
Utc.with_ymd_and_hms(2027, 05, 11, 1, 29, 58).unwrap(),
500500
)),
501501
]),
502502
ASN1Data::Array(vec![
@@ -623,7 +623,7 @@ mod test {
623623

624624
assert_eq!(
625625
obj.into_date().unwrap(),
626-
Utc.ymd(2022, 9, 26).and_hms_milli(10, 0, 0, 0)
626+
Utc.with_ymd_and_hms(2022, 9, 26, 10, 0, 0).unwrap()
627627
);
628628
}
629629

src/utils.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,15 @@ pub(crate) fn get_utc_date_time_from_asn1_milli<T: AsRef<[u8]>>(data: T) -> Resu
6363
};
6464

6565
if let Ok(decoded) = decoded {
66-
Ok(DateTime::<FixedOffset>::from_utc(
67-
NaiveDateTime::parse_from_str(&decoded, format)?,
68-
FixedOffset::east(0),
69-
)
70-
.with_timezone(&Utc))
66+
if let Some(offset) = FixedOffset::east_opt(0) {
67+
Ok(DateTime::<FixedOffset>::from_utc(
68+
NaiveDateTime::parse_from_str(&decoded, format)?,
69+
offset,
70+
)
71+
.with_timezone(&Utc))
72+
} else {
73+
bail!(ASN1NAPIError::MalformedData)
74+
}
7175
} else {
7276
bail!(ASN1NAPIError::MalformedData)
7377
}
@@ -82,12 +86,15 @@ pub(crate) fn get_fixed_date_from_js(data: JsUnknown) -> Result<DateTime<FixedOf
8286
let timestamp = js_date.value_of()? as i64;
8387
let ts_secs = timestamp / 1000;
8488
let ts_ns = ((timestamp % 1000) * 1_000_000) as u32;
85-
let naive = NaiveDateTime::from_timestamp(ts_secs, ts_ns);
8689

87-
Ok(DateTime::<FixedOffset>::from_utc(
88-
naive,
89-
FixedOffset::east(0),
90-
))
90+
if let (Some(datetime), Some(offset)) = (
91+
NaiveDateTime::from_timestamp_opt(ts_secs, ts_ns),
92+
FixedOffset::east_opt(0),
93+
) {
94+
Ok(DateTime::<FixedOffset>::from_utc(datetime, offset))
95+
} else {
96+
bail!(ASN1NAPIError::MalformedData)
97+
}
9198
}
9299

93100
/// Get an ASN1 boolean from a JsUnknown.
@@ -201,14 +208,14 @@ mod test {
201208

202209
#[test]
203210
fn test_get_utc_date_time_from_asn1_milli() {
204-
let date = Utc.ymd(2022, 6, 22).and_hms_milli(18, 18, 0, 210);
211+
let date = Utc.timestamp_millis_opt(1655921880210).unwrap();
205212
let input = [
206213
24, 19, 50, 48, 50, 50, 48, 54, 50, 50, 49, 56, 49, 56, 48, 48, 46, 50, 49, 48, 90,
207214
];
208215

209216
assert_eq!(get_utc_date_time_from_asn1_milli(&input).unwrap(), date);
210217

211-
let date = Utc.ymd(2022, 9, 26).and_hms_milli(10, 0, 0, 0);
218+
let date = Utc.with_ymd_and_hms(2022, 9, 26, 10, 0, 0).unwrap();
212219
let input = [
213220
24, 15, 50, 48, 50, 50, 48, 57, 50, 54, 49, 48, 48, 48, 48, 48, 90,
214221
];

0 commit comments

Comments
 (0)