#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "google_apis/gaia/oauth_request_signer.h"
#include <stddef.h>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <map>
#include <string>
#include "base/base64.h"
#include "base/check.h"
#include "base/format_macros.h"
#include "base/notreached.h"
#include "base/rand_util.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "crypto/hmac.h"
#include "url/gurl.h"
namespace {
const int kHexBase = …;
char kHexDigits[] = …;
const size_t kHmacDigestLength = …;
const int kMaxNonceLength = …;
const int kMinNonceLength = …;
const char kOAuthConsumerKeyLabel[] = …;
const char kOAuthNonceCharacters[] = …;
const char kOAuthNonceLabel[] = …;
const char kOAuthSignatureLabel[] = …;
const char kOAuthSignatureMethodLabel[] = …;
const char kOAuthTimestampLabel[] = …;
const char kOAuthTokenLabel[] = …;
const char kOAuthVersion[] = …;
const char kOAuthVersionLabel[] = …;
enum ParseQueryState { … };
const std::string HttpMethodName(OAuthRequestSigner::HttpMethod method) { … }
const std::string SignatureMethodName(
OAuthRequestSigner::SignatureMethod method) { … }
std::string BuildBaseString(const GURL& request_base_url,
OAuthRequestSigner::HttpMethod http_method,
const std::string& base_parameters) { … }
std::string BuildBaseStringParameters(
const OAuthRequestSigner::Parameters& parameters) { … }
std::string GenerateNonce() { … }
std::string GenerateTimestamp() { … }
bool ParseQuery(const std::string& query,
OAuthRequestSigner::Parameters* parameters_result) { … }
bool SignHmacSha1(const std::string& text,
const std::string& key,
std::string* signature_return) { … }
bool SignPlaintext(const std::string& text,
const std::string& key,
std::string* result) { … }
bool SignRsaSha1(const std::string& text,
const std::string& key,
std::string* result) { … }
void PrepareParameters(OAuthRequestSigner::Parameters* parameters,
OAuthRequestSigner::SignatureMethod signature_method,
OAuthRequestSigner::HttpMethod http_method,
const std::string& consumer_key,
const std::string& token_key) { … }
bool SignParameters(const GURL& request_base_url,
OAuthRequestSigner::SignatureMethod signature_method,
OAuthRequestSigner::HttpMethod http_method,
const std::string& consumer_key,
const std::string& consumer_secret,
const std::string& token_key,
const std::string& token_secret,
OAuthRequestSigner::Parameters* parameters) { … }
}
bool OAuthRequestSigner::Decode(const std::string& text,
std::string* decoded_text) { … }
std::string OAuthRequestSigner::Encode(const std::string& text) { … }
bool OAuthRequestSigner::ParseAndSign(const GURL& request_url_with_parameters,
SignatureMethod signature_method,
HttpMethod http_method,
const std::string& consumer_key,
const std::string& consumer_secret,
const std::string& token_key,
const std::string& token_secret,
std::string* result) { … }
bool OAuthRequestSigner::SignURL(
const GURL& request_base_url,
const Parameters& request_parameters,
SignatureMethod signature_method,
HttpMethod http_method,
const std::string& consumer_key,
const std::string& consumer_secret,
const std::string& token_key,
const std::string& token_secret,
std::string* signed_text_return) { … }
bool OAuthRequestSigner::SignAuthHeader(
const GURL& request_base_url,
const Parameters& request_parameters,
SignatureMethod signature_method,
HttpMethod http_method,
const std::string& consumer_key,
const std::string& consumer_secret,
const std::string& token_key,
const std::string& token_secret,
std::string* signed_text_return) { … }