Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 1717610 - Add function to get seconds from epoch from pkix::Time …
…r=bbeurdouche,keeler

We need this function for the rewrite of CertVerifier::VerifyCertificateTransparencyPolicy in order to calculate a certificate's lifetime in months.

Differential Revision: https://phabricator.services.mozilla.com/D118525

--HG--
extra : moz-landing-system : lando
  • Loading branch information
R. Martinho Fernandes committed Jun 24, 2021
1 parent 5981b7f commit 35c3550
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/mozpkix/include/pkix/Time.h
Expand Up @@ -111,6 +111,9 @@ Time Now();
// Note the epoch is the unix epoch (ie 00:00:00 UTC, 1 January 1970)
Time TimeFromEpochInSeconds(uint64_t secondsSinceEpoch);

// Note the epoch is the unix epoch (ie 00:00:00 UTC, 1 January 1970)
Result SecondsSinceEpochFromTime(Time time, uint64_t* outSeconds);

class Duration final {
public:
Duration(Time timeA, Time timeB)
Expand All @@ -129,6 +132,8 @@ class Duration final {
}

private:
friend Result SecondsSinceEpochFromTime(Time time, uint64_t* outSeconds);

uint64_t durationInSeconds;
};
}
Expand Down
14 changes: 14 additions & 0 deletions lib/mozpkix/lib/pkixtime.cpp
Expand Up @@ -75,4 +75,18 @@ TimeFromEpochInSeconds(uint64_t secondsSinceEpoch)
return TimeFromElapsedSecondsAD(seconds);
}

Result
SecondsSinceEpochFromTime(Time time, uint64_t* outSeconds)
{
if (!outSeconds) {
return Result::FATAL_ERROR_INVALID_ARGS;
}
Time epoch = TimeFromEpochInSeconds(0);
if (time < epoch) {
return Result::FATAL_ERROR_INVALID_ARGS;
}
*outSeconds = Duration(time, epoch).durationInSeconds;
return Result::Success;
}

} } // namespace mozilla::pkix

0 comments on commit 35c3550

Please sign in to comment.