Actually call on_reset callback
[lsnes.git] / include / library / httpauth.hpp
bloba8101f85409004e5b6809c311e9a42b13bced8db
1 #ifndef _library__httpauth__hpp__included__
2 #define _library__httpauth__hpp__included__
4 #include "skein.hpp"
5 #include <string>
6 #include <cstring>
7 #include <list>
8 #include <map>
10 /**
11 * DH25519 HTTP auth class.
13 class dh25519_http_auth
15 public:
16 /**
17 * Internal hashing instance.
19 class request_hash
21 public:
22 /**
23 * Construct.
25 request_hash(const std::string& _id, const uint8_t* _key, unsigned _nonce, skein::hash _h,
26 const uint8_t* _prereq)
27 : id(_id), nonce(_nonce), h(_h)
29 memcpy(pubkey, _key, 32);
30 memcpy(prereq, _prereq, 8);
32 /**
33 * Append data to hash.
35 void hash(const uint8_t* data, size_t datalen)
37 h.write(data, datalen);
39 /**
40 * Read the final Authorization header.
42 std::string get_authorization();
43 private:
44 std::string id;
45 uint8_t pubkey[32];
46 uint8_t prereq[8];
47 unsigned nonce;
48 skein::hash h;
50 /**
51 * Create a new instance.
53 * Parameter privkey: The private key (32 bytes).
55 dh25519_http_auth(const uint8_t* privkey);
56 /**
57 * Dtor.
59 ~dh25519_http_auth();
60 /**
61 * Format a session creation request
63 * Returns: The value for Authorization header.
65 std::string format_get_session_request();
66 /**
67 * Start request hash computation. Hashes in the shared secret and nonce. The nonce is incremented.
69 * Parameter url: The notional URL.
70 * Returns: The skein hash instance.
72 request_hash start_request(const std::string& url, const std::string& verb);
73 /**
74 * Parse session auth response. If it contains new session parameters, the session is updated.
76 * Parameter response: The response from server (WWW-Authenticate).
78 void parse_auth_response(const std::string& response);
79 /**
80 * Is the session ready?
82 bool is_ready() { return ready; }
83 /**
84 * Output pubkey.
86 void get_pubkey(uint8_t* pubkey);
87 private:
88 void parse_auth_response(std::map<std::string, std::string> pparse);
89 unsigned char privkey[32];
90 unsigned char pubkey[32];
91 unsigned char ssecret[32];
92 std::string id;
93 unsigned nonce;
94 bool ready; //id&ssecret is valid.
97 #endif