@@ -622,33 +622,36 @@ namespace brssl {
622
622
};
623
623
624
624
625
+ namespace BearSSL {
626
+
627
+
625
628
// ----- Public Key -----
626
629
627
- BearSSLPublicKey::BearSSLPublicKey () {
630
+ PublicKey::PublicKey () {
628
631
_key = nullptr ;
629
632
}
630
633
631
- BearSSLPublicKey::BearSSLPublicKey (const char *pemKey) {
634
+ PublicKey::PublicKey (const char *pemKey) {
632
635
_key = nullptr ;
633
636
parse (pemKey);
634
637
}
635
638
636
- BearSSLPublicKey::BearSSLPublicKey (const uint8_t *derKey, size_t derLen) {
639
+ PublicKey::PublicKey (const uint8_t *derKey, size_t derLen) {
637
640
_key = nullptr ;
638
641
parse (derKey, derLen);
639
642
}
640
643
641
- BearSSLPublicKey ::~BearSSLPublicKey () {
644
+ PublicKey ::~PublicKey () {
642
645
if (_key) {
643
646
brssl::free_public_key (_key);
644
647
}
645
648
}
646
649
647
- bool BearSSLPublicKey ::parse (const char *pemKey) {
650
+ bool PublicKey ::parse (const char *pemKey) {
648
651
return parse ((const uint8_t *)pemKey, strlen_P (pemKey));
649
652
}
650
653
651
- bool BearSSLPublicKey ::parse (const uint8_t *derKey, size_t derLen) {
654
+ bool PublicKey ::parse (const uint8_t *derKey, size_t derLen) {
652
655
if (_key) {
653
656
brssl::free_public_key (_key);
654
657
_key = nullptr ;
@@ -657,28 +660,28 @@ bool BearSSLPublicKey::parse(const uint8_t *derKey, size_t derLen) {
657
660
return _key ? true : false ;
658
661
}
659
662
660
- bool BearSSLPublicKey ::isRSA () const {
663
+ bool PublicKey ::isRSA () const {
661
664
if (!_key || _key->key_type != BR_KEYTYPE_RSA) {
662
665
return false ;
663
666
}
664
667
return true ;
665
668
}
666
669
667
- bool BearSSLPublicKey ::isEC () const {
670
+ bool PublicKey ::isEC () const {
668
671
if (!_key || _key->key_type != BR_KEYTYPE_EC) {
669
672
return false ;
670
673
}
671
674
return true ;
672
675
}
673
676
674
- const br_rsa_public_key *BearSSLPublicKey ::getRSA () const {
677
+ const br_rsa_public_key *PublicKey ::getRSA () const {
675
678
if (!_key || _key->key_type != BR_KEYTYPE_RSA) {
676
679
return nullptr ;
677
680
}
678
681
return &_key->key .rsa ;
679
682
}
680
683
681
- const br_ec_public_key *BearSSLPublicKey ::getEC () const {
684
+ const br_ec_public_key *PublicKey ::getEC () const {
682
685
if (!_key || _key->key_type != BR_KEYTYPE_EC) {
683
686
return nullptr ;
684
687
}
@@ -687,31 +690,31 @@ const br_ec_public_key *BearSSLPublicKey::getEC() const {
687
690
688
691
// ----- Private Key -----
689
692
690
- BearSSLPrivateKey::BearSSLPrivateKey () {
693
+ PrivateKey::PrivateKey () {
691
694
_key = nullptr ;
692
695
}
693
696
694
- BearSSLPrivateKey::BearSSLPrivateKey (const char *pemKey) {
697
+ PrivateKey::PrivateKey (const char *pemKey) {
695
698
_key = nullptr ;
696
699
parse (pemKey);
697
700
}
698
701
699
- BearSSLPrivateKey::BearSSLPrivateKey (const uint8_t *derKey, size_t derLen) {
702
+ PrivateKey::PrivateKey (const uint8_t *derKey, size_t derLen) {
700
703
_key = nullptr ;
701
704
parse (derKey, derLen);
702
705
}
703
706
704
- BearSSLPrivateKey ::~BearSSLPrivateKey () {
707
+ PrivateKey ::~PrivateKey () {
705
708
if (_key) {
706
709
brssl::free_private_key (_key);
707
710
}
708
711
}
709
712
710
- bool BearSSLPrivateKey ::parse (const char *pemKey) {
713
+ bool PrivateKey ::parse (const char *pemKey) {
711
714
return parse ((const uint8_t *)pemKey, strlen_P (pemKey));
712
715
}
713
716
714
- bool BearSSLPrivateKey ::parse (const uint8_t *derKey, size_t derLen) {
717
+ bool PrivateKey ::parse (const uint8_t *derKey, size_t derLen) {
715
718
if (_key) {
716
719
brssl::free_private_key (_key);
717
720
_key = nullptr ;
@@ -720,68 +723,70 @@ bool BearSSLPrivateKey::parse(const uint8_t *derKey, size_t derLen) {
720
723
return _key ? true : false ;
721
724
}
722
725
723
- bool BearSSLPrivateKey ::isRSA () const {
726
+ bool PrivateKey ::isRSA () const {
724
727
if (!_key || _key->key_type != BR_KEYTYPE_RSA) {
725
728
return false ;
726
729
}
727
730
return true ;
728
731
}
729
732
730
- bool BearSSLPrivateKey ::isEC () const {
733
+ bool PrivateKey ::isEC () const {
731
734
if (!_key || _key->key_type != BR_KEYTYPE_EC) {
732
735
return false ;
733
736
}
734
737
return true ;
735
738
}
736
739
737
- const br_rsa_private_key *BearSSLPrivateKey ::getRSA () const {
740
+ const br_rsa_private_key *PrivateKey ::getRSA () const {
738
741
if (!_key || _key->key_type != BR_KEYTYPE_RSA) {
739
742
return nullptr ;
740
743
}
741
744
return &_key->key .rsa ;
742
745
}
743
746
744
- const br_ec_private_key *BearSSLPrivateKey ::getEC () const {
747
+ const br_ec_private_key *PrivateKey ::getEC () const {
745
748
if (!_key || _key->key_type != BR_KEYTYPE_EC) {
746
749
return nullptr ;
747
750
}
748
751
return &_key->key .ec ;
749
752
}
750
753
751
- BearSSLX509List::BearSSLX509List () {
754
+ // ----- Certificate Lists -----
755
+
756
+ X509List::X509List () {
752
757
_count = 0 ;
753
758
_cert = nullptr ;
754
759
_ta = nullptr ;
755
760
}
756
761
757
- BearSSLX509List::BearSSLX509List (const char *pemCert) {
762
+ X509List::X509List (const char *pemCert) {
758
763
_count = 0 ;
759
764
_cert = nullptr ;
760
765
_ta = nullptr ;
761
766
append (pemCert);
762
767
}
763
768
764
769
765
- BearSSLX509List::BearSSLX509List (const uint8_t *derCert, size_t derLen) {
770
+ X509List::X509List (const uint8_t *derCert, size_t derLen) {
766
771
_count = 0 ;
767
772
_cert = nullptr ;
768
773
_ta = nullptr ;
769
774
append (derCert, derLen);
770
775
}
771
776
772
- BearSSLX509List ::~BearSSLX509List () {
777
+ X509List ::~X509List () {
773
778
brssl::free_certificates (_cert, _count); // also frees cert
774
779
for (size_t i = 0 ; i < _count; i++) {
775
780
brssl::free_ta_contents (&_ta[i]);
776
781
}
777
782
free (_ta);
778
783
}
779
784
780
- bool BearSSLX509List ::append (const char *pemCert) {
785
+ bool X509List ::append (const char *pemCert) {
781
786
return append ((const uint8_t *)pemCert, strlen_P (pemCert));
782
787
}
783
788
784
- bool BearSSLX509List ::append (const uint8_t *derCert, size_t derLen) {
789
+ bool X509List ::append (const uint8_t *derCert, size_t derLen) {
785
790
size_t numCerts;
786
791
br_x509_certificate *newCerts = brssl::read_certificates ((const char *)derCert, derLen, &numCerts);
787
792
if (!newCerts) {
@@ -819,3 +824,6 @@ bool BearSSLX509List::append(const uint8_t *derCert, size_t derLen) {
819
824
820
825
return true ;
821
826
}
827
+
828
+ };
829
+
0 commit comments