File tree Expand file tree Collapse file tree 26 files changed +2241
-0
lines changed
Expand file tree Collapse file tree 26 files changed +2241
-0
lines changed Original file line number Diff line number Diff line change 1+ [submodule "thirdparty/rapidjson "]
2+ path = thirdparty/rapidjson
3+ url = https://github.com/miloyip/rapidjson.git
Original file line number Diff line number Diff line change 1+ cmake_minimum_required (VERSION 2.8)
2+ project (libjose)
3+ add_subdirectory (src)
4+ add_subdirectory (tests)
Original file line number Diff line number Diff line change 1+ #ifndef __LIBJOSE_CONFIG_HPP__
2+ #define __LIBJOSE_CONFIG_HPP__
3+
4+ #ifndef __cplusplus
5+ #error this header is for C++.
6+ #endif
7+
8+ #include < string>
9+ typedef std::basic_string<unsigned char > ustring;
10+ static inline ustring to_ustring (const std::string &str) {
11+ return ustring (str.begin (), str.end ());
12+ }
13+ static inline std::string to_string (const ustring &str) {
14+ return std::string (str.begin (), str.end ());
15+ }
16+
17+ #endif // __LIBJOSE_CONFIG_HPP__
Original file line number Diff line number Diff line change 1+ #ifndef __LIBJOSE_EXCEPTION_HPP___
2+ #define __LIBJOSE_EXCEPTION_HPP___
3+
4+ #include " config.hpp"
5+ #include < stdexcept>
6+
7+ namespace JOSE {
8+
9+ } // namespace JOSE
10+
11+ #endif // __LIBJOSE_EXCEPTION_HPP___
Original file line number Diff line number Diff line change 1+ #ifndef __LIBJOSE_JOSE_HPP__
2+ #define __LIBJOSE_JOSE_HPP__
3+
4+ #include " config.hpp"
5+ #include < string>
6+
7+ namespace JOSE {
8+
9+ class JOSE {
10+ public:
11+ JOSE ();
12+ explicit JOSE (const std::string &json);
13+ ~JOSE ();
14+ operator bool () const {return valid_;}
15+ private:
16+ friend class JWA_OCT ;
17+ friend class JWA_RSA ;
18+ friend class JWA_EC ;
19+ JOSE (void *);
20+
21+ void *_;
22+ bool valid_;
23+ };
24+
25+ } // namespace JOSE
26+
27+ #endif // __LIBJOSE_JOSE_HPP__
Original file line number Diff line number Diff line change 1+ #ifndef __LIBJOSE_JWA_HPP__
2+ #define __LIBJOSE_JWA_HPP__
3+
4+ #include " config.hpp"
5+ #include < string>
6+ #include " jwa_ec.hpp"
7+
8+ namespace JOSE {
9+
10+ class JWA_OCT ;
11+ class JWA_RSA ;
12+ class JWA_EC ;
13+
14+ class JWA {
15+ public:
16+ struct KeyType {
17+ enum Type {
18+ OCT,
19+ RSA,
20+ EC,
21+ };
22+ };
23+ struct JWEAlg {
24+ enum Type {
25+ RSA1_5,
26+ RSA_OAEP,
27+ RSA_OAEP_256,
28+ A128KW,
29+ A192KW,
30+ A256KW,
31+ DIRECT,
32+ ECDH_ES,
33+ ECDH_ES_A128KW,
34+ ECDH_ES_A192KW,
35+ ECDH_ES_A256KW,
36+ A128GCMKW,
37+ A192GCMKW,
38+ A256GCMKW,
39+ PBES2_HS256_A128KW,
40+ PBES2_HS384_A192KW,
41+ PBES2_HS512_A256KW,
42+ };
43+ };
44+ JWA ();
45+ explicit JWA (const std::string &json);
46+ ~JWA ();
47+ operator bool () const {return valid_;}
48+ std::string to_pem () const ;
49+ const KeyType::Type &kty () const ;
50+ JWA_OCT &oct () { return *jwaimpl_.oct ; }
51+ const JWA_OCT &oct () const { return *jwaimpl_.oct ; }
52+ JWA_RSA &rsa () { return *jwaimpl_.rsa ; }
53+ const JWA_RSA &rsa () const { return *jwaimpl_.rsa ; }
54+ JWA_EC &ec () { return *jwaimpl_.ec ; }
55+ const JWA_EC &ec () const { return *jwaimpl_.ec ; }
56+ private:
57+ friend class JWK ;
58+ JWA (void *);
59+ void init_ ();
60+
61+ void *_;
62+ union {
63+ JWA_OCT *oct;
64+ JWA_RSA *rsa;
65+ JWA_EC *ec;
66+ } jwaimpl_;
67+ bool valid_;
68+ };
69+
70+ } // namespace JOSE
71+
72+ #endif // __LIBJOSE_JWA_HPP__
Original file line number Diff line number Diff line change 1+ #ifndef __LIBJOSE_JWA_EC_HPP__
2+ #define __LIBJOSE_JWA_EC_HPP__
3+
4+ #include " config.hpp"
5+ #include < string>
6+ #include " jose.hpp"
7+ #include " jwa.hpp"
8+
9+ namespace JOSE {
10+
11+ class JWA_EC {
12+ public:
13+ JWA_EC ();
14+ explicit JWA_EC (const std::string &);
15+ ~JWA_EC ();
16+ operator bool () const {return valid_;}
17+ std::string to_pem () const ;
18+ private:
19+ friend class JWA ;
20+ JWA_EC (void *);
21+ void init_ ();
22+
23+ void *_;
24+ JOSE jose_;
25+ bool valid_;
26+ };
27+
28+ } // namespace JOSE
29+
30+ #endif // __LIBJOSE_JWA_EC_HPP__
Original file line number Diff line number Diff line change 1+ #ifndef __LIBJOSE_JWA_OCT_HPP__
2+ #define __LIBJOSE_JWA_OCT_HPP__
3+
4+ #include " config.hpp"
5+ #include < string>
6+ #include " jose.hpp"
7+ #include " jwa.hpp"
8+
9+ namespace JOSE {
10+
11+ class JWA_OCT {
12+ public:
13+ JWA_OCT ();
14+ explicit JWA_OCT (const std::string &);
15+ ~JWA_OCT ();
16+ operator bool () const {return valid_;}
17+ const std::string & k () const ;
18+ private:
19+ friend class JWA ;
20+ JWA_OCT (void *);
21+ void init_ ();
22+
23+ void *_;
24+ JOSE jose_;
25+ bool valid_;
26+ };
27+
28+ } // namespace JOSE
29+
30+ #endif // __LIBJOSE_JWA_OCT_HPP__
Original file line number Diff line number Diff line change 1+ #ifndef __LIBJOSE_JWA_RSA_HPP__
2+ #define __LIBJOSE_JWA_RSA_HPP__
3+
4+ #include " config.hpp"
5+ #include < string>
6+ #include " jose.hpp"
7+ #include " jwa.hpp"
8+
9+ namespace JOSE {
10+
11+ class JWA_RSA {
12+ public:
13+ JWA_RSA ();
14+ explicit JWA_RSA (const std::string &);
15+ ~JWA_RSA ();
16+ operator bool () const {return valid_;}
17+ std::string to_pem () const ;
18+ std::string n () const ;
19+ const ustring & n_raw () const ;
20+ std::string e () const ;
21+ const ustring & e_raw () const ;
22+ std::string d () const ;
23+ const ustring & d_raw () const ;
24+ std::string p () const ;
25+ const ustring & p_raw () const ;
26+ std::string q () const ;
27+ const ustring & q_raw () const ;
28+ std::string dp () const ;
29+ const ustring & dp_raw () const ;
30+ std::string dq () const ;
31+ const ustring & dq_raw () const ;
32+ std::string qi () const ;
33+ const ustring & qi_raw () const ;
34+ private:
35+ friend class JWA ;
36+ JWA_RSA (void *);
37+ void init_ ();
38+
39+ void *_;
40+ JOSE jose_;
41+ bool valid_;
42+ };
43+
44+ } // namespace JOSE
45+
46+ #endif // __LIBJOSE_JWA_RSA_HPP__
Original file line number Diff line number Diff line change 1+ #ifndef __LIBJOSE_JWK_HPP__
2+ #define __LIBJOSE_JWK_HPP__
3+
4+ #include " config.hpp"
5+ #include < string>
6+ #include " exception.hpp"
7+ #include " jwa.hpp"
8+
9+ namespace JOSE {
10+
11+ class JWK {
12+ public:
13+ JWK (const std::string &json);
14+ JWK ();
15+ ~JWK ();
16+ operator bool () const {return valid_;}
17+ const std::string &use () const ;
18+ const std::string &key_opts () const ;
19+ const std::string &alg () const ;
20+ const std::string &kid () const ;
21+ const std::string &x5u () const ;
22+ const std::string &x5t () const ;
23+ const std::string &x5t_S256 () const ;
24+ const JWA &jwa () const {return jwa_;}
25+ JWA &jwa () {return jwa_;}
26+ std::string to_json () const ;
27+ std::string to_pem () const {return jwa_.to_pem ();}
28+ private:
29+ void *_;
30+ JWA jwa_;
31+ bool valid_;
32+ };
33+
34+ } // namespace JOSE
35+
36+ #endif // __LIBJOSE_JWK_HPP__
You can’t perform that action at this time.
0 commit comments