Skip to content

Commit

Permalink
Increase coverage (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
troian authored Oct 23, 2019
1 parent 8dd658e commit 1db80a4
Show file tree
Hide file tree
Showing 6 changed files with 477 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ if (WITH_TESTS)
tests/hmac.cpp
tests/rsa.cpp
tests/pss.cpp
tests/digest.cpp
tests/header.cpp
)

add_executable(josepp_test ${JOSEPP_TEST_SRS})
Expand Down
7 changes: 1 addition & 6 deletions src/digest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@ namespace jose {

digest::digest(digest::type type, const uint8_t *in_data, size_t in_size)
: _size(SHA256_DIGEST_LENGTH)
, _data(nullptr) {
try {
_data = std::shared_ptr<uint8_t>(new uint8_t[SHA512_DIGEST_LENGTH], std::default_delete<uint8_t[]>());
} catch (...) {
throw;
}
, _data(new uint8_t[SHA512_DIGEST_LENGTH], std::default_delete<uint8_t[]>()) {

switch (type) {
case digest::type::SHA256: {
Expand Down
16 changes: 16 additions & 0 deletions src/header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ hdr::hdr(const std::string &data)
: _h()
{
std::stringstream(data) >> _h;

if (!_h.isMember("typ") || !_h["typ"].isString()) {
throw std::runtime_error("stream does not have valid \"typ\" field");
}

if (_h["typ"].asString() != "JWT") {
throw std::runtime_error("invalid \"typ\" value");
}

if (!_h.isMember("alg") || !_h["alg"].isString()) {
throw std::runtime_error("stream does not have valid \"alg\" field");
}

if (jose::crypto::str2alg(_h["alg"].asString()) == jose::alg::UNKNOWN) {
throw std::runtime_error("invalid \"alg\" value");
}
}

std::string hdr::b64() {
Expand Down
Loading

0 comments on commit 1db80a4

Please sign in to comment.