• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 23969876719

04 Apr 2026 02:57AM UTC coverage: 89.456% (-0.04%) from 89.494%
23969876719

push

github

web-flow
Merge pull request #5514 from randombit/jack/ber-decoder-limits

Add BER_Decoder::Limits

105558 of 118000 relevant lines covered (89.46%)

11583859.33 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.3
/src/lib/pubkey/x509_key.cpp
1
/*
2
* X.509 Public Key
3
* (C) 1999-2010 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include <botan/x509_key.h>
9

10
#include <botan/asn1_obj.h>
11
#include <botan/ber_dec.h>
12
#include <botan/data_src.h>
13
#include <botan/pem.h>
14
#include <botan/pk_algs.h>
15

16
namespace Botan::X509 {
17

18
/*
19
* PEM encode a X.509 public key
20
*/
21
std::string PEM_encode(const Public_Key& key) {
387✔
22
   return PEM_Code::encode(key.subject_public_key(), "PUBLIC KEY");
1,161✔
23
}
24

25
/*
26
* Extract a public key and return it
27
*/
28
std::unique_ptr<Public_Key> load_key(DataSource& source) {
15,261✔
29
   try {
15,261✔
30
      AlgorithmIdentifier alg_id;
15,261✔
31
      std::vector<uint8_t> key_bits;
15,261✔
32

33
      if(ASN1::maybe_BER(source) && !PEM_Code::matches(source)) {
15,261✔
34
         BER_Decoder(source, BER_Decoder::Limits::DER())
30,126✔
35
            .start_sequence()
30,126✔
36
            .decode(alg_id)
15,063✔
37
            .decode(key_bits, ASN1_Type::BitString)
15,063✔
38
            .end_cons()
15,063✔
39
            .verify_end();
15,063✔
40
      } else {
41
         DataSource_Memory ber(PEM_Code::decode_check_label(source, "PUBLIC KEY"));
198✔
42

43
         BER_Decoder(ber, BER_Decoder::Limits::DER())
302✔
44
            .start_sequence()
302✔
45
            .decode(alg_id)
151✔
46
            .decode(key_bits, ASN1_Type::BitString)
151✔
47
            .end_cons()
151✔
48
            .verify_end();
151✔
49
      }
151✔
50

51
      if(key_bits.empty()) {
15,214✔
52
         throw Decoding_Error("X.509 public key decoding");
×
53
      }
54

55
      return load_public_key(alg_id, key_bits);
30,390✔
56
   } catch(Decoding_Error& e) {
15,393✔
57
      throw Decoding_Error("X.509 public key decoding", e);
132✔
58
   }
132✔
59
}
60

61
}  // namespace Botan::X509
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc