This repository has been archived by the owner on Aug 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OAuthUtils.h
77 lines (74 loc) · 2.97 KB
/
OAuthUtils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef OAUTHUTILS_H
#define OAUTHUTILS_H
#include "CString.h"
#include "OAuthUtils.h"
#include "MD5.h"
#include "SHA256.h"
/* Qt includes */
#include <QUrl>
#include <QHash>
#include <QCryptographicHash>
/* Other includes */
#include <set>
#include <string>
#include <vector>
#include <list>
#include <sstream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <map>
#include <iostream>
using namespace std;
using std::map;
using std::set;
using std::string;
using std::vector;
using std::list;
using std::pair;
using std::stringstream;
class OAuthUtils;
/** @brief OAuth utilities that are used internally. */
class OAuthUtils {
public:
/** @brief Only required to create nonce strings
* @param uLength Lenght of the nonce string.
* @return A nonce string, internally required for OAuth. */
static CString Nonce(unsigned int uLength);
/** @brief This is only internally used to make OAuth signatures */
static CString HMACSHA1(CString& sInput, CString& sKey);
/** @brief Used internally to generate signatures
* @param sHTTPMethod The HTTP Method for the request
* @param sNormURL The URL in the request
* @param sParams The parameters, joined with JoinParams
* @return The actually signature */
static CString GenerateSignature(CString sHTTPMethod, CString sNormURL, CString sParams);
/** @brief Used internally to generate signatures
* @param sHTTPMethod The HTTP Method for the request
* @param sNormURL The URL in the request
* @param Params A map with the parameters
* @return The actually signature */
static CString GenerateSignature(CString sHTTPMethod, CString sNormURL, std::map<CString, CString> Params);
/** @brief Only used internally to join parameters into a string
* @param Params A map with the parameters
* @return String with the joined parameters */
static CString JoinParams(std::map<CString, CString> Params);
/** @brief Only used internally to join parameters into a string for urls
* @param urlParams A map with the parameters to join
* @return String with the joined parameters, ready to be used in a GET request */
static CString JoinUrlParams(std::map<CString, CString> urlParams);
/** @brief Only used internally to join parameters into a string for post requests
* @param postParams A map with the parameters to join
* @param encode Should they be encoded?
* @return String with the joined parameters, ready to be used in a POST request */
static CString JoinPostParams(std::map<CString, CString> postParams, bool encode = false);
/** @brief Easy function to actually create the render
* @param Params A map with all the parameters that have to be in the header
* @return The actual header */
static CString RenderHeader(std::map<CString, CString> Params);
/** @brief Used to parse data from the received headers
* @param input The raw headers
* @param wantedField The field we want as output */
static CString parseHeader(CString input, CString wantedField);
};
#endif // !OAUTHUTILS_H