Skip to content

Commit

Permalink
IOS/ESFormats: Add ParseCertChain
Browse files Browse the repository at this point in the history
This will be used to avoid duplicating cert chain parsing code.
  • Loading branch information
leoetlino committed Jun 12, 2017
1 parent fd9fb03 commit 5571fc8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Source/Core/Core/IOS/ES/Formats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,5 +676,23 @@ std::vector<u8> CertReader::GetPublicKey() const
const auto key_begin = m_bytes.begin() + info.first;
return std::vector<u8>(key_begin, key_begin + info.second);
}

std::map<std::string, CertReader> ParseCertChain(const std::vector<u8>& chain)
{
std::map<std::string, CertReader> certs;

size_t processed = 0;
while (processed != chain.size())
{
CertReader cert_reader{std::vector<u8>(chain.begin() + processed, chain.end())};
if (!cert_reader.IsValid())
return certs;

processed += cert_reader.GetBytes().size();
const std::string name = cert_reader.GetName();
certs.emplace(std::move(name), std::move(cert_reader));
}
return certs;
}
} // namespace ES
} // namespace IOS
2 changes: 2 additions & 0 deletions Source/Core/Core/IOS/ES/Formats.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,5 +284,7 @@ class CertReader final : public SignedBlobReader
private:
bool m_is_valid = false;
};

std::map<std::string, CertReader> ParseCertChain(const std::vector<u8>& chain);
} // namespace ES
} // namespace IOS

0 comments on commit 5571fc8

Please sign in to comment.