Skip to content

Commit

Permalink
fix(compat): update v1 date parser
Browse files Browse the repository at this point in the history
Signed-off-by: Universal Studio <[email protected]>
  • Loading branch information
TMUniversal committed Aug 6, 2024
1 parent 28fe7a8 commit a66c115
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
8 changes: 4 additions & 4 deletions cmd/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ const doc = `# PaperCrypt Version: 2.0.0
# Content Serial: EIPESR
# Purpose: Example Sheet
# Comment: Regular PDF Example
# Date: Thu, 01 Aug 2024 20:38:10.306596100 CEST
# Date: Thu, 01 Aug 2024 20:38:10.306596100 +0200
# Data Format: PGP
# Content Length: 390
# Content CRC-24: d6f1c0
# Content CRC-32: bc4b3672
# Content SHA-256: NT7wwW5Tq5fk1J82M1tzE82VGxIlad5vpF5cDMzg+yg=
# Header CRC-32: c2eee21
# Header CRC-32: ecded03b
1: 1F 8B 08 00 00 00 00 00 02 FF 00 6A 01 95 FE C3 2E 04 09 03 08 7A D49E51
Expand All @@ -112,13 +112,13 @@ const docRaw = `# PaperCrypt Version: 2.0.0
# Content Serial: BVC36O
# Purpose: Example Sheet
# Comment: Regular PDF Example
# Date: Sun, 04 Aug 2024 12:36:20.800974400 CEST
# Date: Sun, 04 Aug 2024 12:36:20.800974400 +0200
# Data Format: Raw
# Content Length: 261
# Content CRC-24: ce50b7
# Content CRC-32: 5f6b9b4b
# Content SHA-256: w8b3gibx3gdQsGXmlWVtET631gMT0TDLbe94IC5hXuw=
# Header CRC-32: 225bb1ed
# Header CRC-32: 3967f39
1: 1F 8B 08 00 00 00 00 00 02 FF 8C 90 3F 6B F3 30 10 C6 77 7F 0A A1 39 B6 C7FEC2
Expand Down
12 changes: 7 additions & 5 deletions internal/container_file_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,7 @@ func (p *PaperCryptV1) GetText(lowerCaseEncoding bool) ([]byte, error) {
HeaderFieldComment,
p.Comment,
HeaderFieldDate,
// format time with nanosecond precision
// Sat, 12 Aug 2023 17:33:20.123456789
p.CreatedAt.Format("Mon, 02 Jan 2006 15:04:05.000000000 MST"),
p.CreatedAt.Format(TimeStampFormatLongTZ),
HeaderFieldContentLength,
p.GetLength(),
HeaderFieldCRC24,
Expand Down Expand Up @@ -336,9 +334,13 @@ func DeserializeV1Text(data []byte, ignoreVersionMismatch bool, ignoreChecksumMi
log.Warn(Warning("Date not present in header!"))
}

timestamp, err := time.Parse("Mon, 02 Jan 2006 15:04:05.000000000 MST", headerDate)
timestamp, err := time.Parse(TimeStampFormatLongTZ, headerDate)
if err != nil {
return nil, errors.Join(errors.New("invalid date format"), err)
// try parsing with -0700 over MST
timestamp, err = time.Parse(TimeStampFormatLong, headerDate)
if err != nil {
return nil, errors.Join(errors.New("invalid date format"), err)
}
}

// we don't need to pass the checksums, as they are already verified
Expand Down
3 changes: 2 additions & 1 deletion internal/timestamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
package internal

const (
TimeStampFormatLong = "Mon, 02 Jan 2006 15:04:05.000000000 MST"
TimeStampFormatLong = "Mon, 02 Jan 2006 15:04:05.000000000 -0700"
TimeStampFormatLongTZ = "Mon, 02 Jan 2006 15:04:05.000000000 MST"
TimeStampFormatShort = "2006-01-02 15:04:05"
TimeStampFormatDate = "2006-01-02"
TimeStampFormatPDFHeader = "2006-01-02 15:04 -0700"
Expand Down

0 comments on commit a66c115

Please sign in to comment.