Skip to content

Commit

Permalink
Don't require std::string for DER decode
Browse files Browse the repository at this point in the history
  • Loading branch information
Sainan committed Jan 22, 2025
1 parent da14850 commit 8b4a8ba
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions soup/Asn1Sequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ NAMESPACE_SOUP
return fromDer(r);
}

Asn1Sequence Asn1Sequence::fromDer(const char* data, size_t size)
{
MemoryRefReader r(data, size);
return fromDer(r);
}

Asn1Sequence Asn1Sequence::fromDer(Reader& r) SOUP_EXCAL
{
SOUP_IF_UNLIKELY (readIdentifier(r).type != ASN1_SEQUENCE)
Expand Down
1 change: 1 addition & 0 deletions soup/Asn1Sequence.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ NAMESPACE_SOUP
explicit Asn1Sequence(const std::string& data) SOUP_EXCAL; // expects DER-encoded data without prefix

[[nodiscard]] static Asn1Sequence fromDer(const std::string& str) SOUP_EXCAL; // expects DER-encoded data with prefix
[[nodiscard]] static Asn1Sequence fromDer(const char* data, size_t size) SOUP_EXCAL; // expects DER-encoded data with prefix
[[nodiscard]] static Asn1Sequence fromDer(Reader& r) SOUP_EXCAL; // expects DER-encoded data with prefix

[[nodiscard]] size_t countChildren() const;
Expand Down
5 changes: 5 additions & 0 deletions soup/X509Certificate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ NAMESPACE_SOUP
return load(Asn1Sequence::fromDer(str));
}

bool X509Certificate::fromDer(const char* data, size_t size) noexcept
{
return load(Asn1Sequence::fromDer(data, size));
}

bool X509Certificate::load(const Asn1Sequence& cert) noexcept
{
SOUP_TRY
Expand Down
1 change: 1 addition & 0 deletions soup/X509Certificate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ NAMESPACE_SOUP
std::time_t valid_to;

bool fromDer(const std::string& str) noexcept;
bool fromDer(const char* data, size_t size) noexcept;
bool load(const Asn1Sequence& cert) noexcept;

[[nodiscard]] bool isRsa() const noexcept { return !is_ec; }
Expand Down

0 comments on commit 8b4a8ba

Please sign in to comment.