libqtaws  0.1.0
UnofficialAWSlibraryforQt-InternalDocumentation
Public Member Functions | Friends | List of all members
AwsSignatureV2 Class Reference

Implements AWS Signature Version 2. More...

Inheritance diagram for AwsSignatureV2:
Inheritance graph
[legend]
Collaboration diagram for AwsSignatureV2:
Collaboration graph
[legend]

Public Member Functions

 AwsSignatureV2 (const QCryptographicHash::Algorithm hashAlgorithm=QCryptographicHash::Sha256)
 Constructs a new AwsSignatureV2 object. More...
 
virtual void sign (const AwsAbstractCredentials &credentials, const QNetworkAccessManager::Operation operation, QNetworkRequest &request, const QByteArray &data=QByteArray()) const
 Sign an AWS request. More...
 
virtual int version () const
 AWS Signature version implemented by this class. More...
 
- Public Member Functions inherited from AwsAbstractSignature
 AwsAbstractSignature ()
 Initialises an AwsAbstractSignature object. More...
 
virtual ~AwsAbstractSignature ()
 AwsAbstractSignature destructor.
 

Friends

class TestAwsSignatureV2
 

Additional Inherited Members

- Protected Member Functions inherited from AwsAbstractSignature
 AwsAbstractSignature (AwsAbstractSignaturePrivate *const d)
 Initialises an AwsAbstractSignature object. More...
 
- Protected Attributes inherited from AwsAbstractSignature
AwsAbstractSignaturePrivate *const d_ptr
 Internal d-pointer.
 

Detailed Description

Implements AWS Signature Version 2.

See also
http://docs.aws.amazon.com/general/latest/gr/signature-version-2.html

Definition at line 32 of file awssignaturev2.h.

Constructor & Destructor Documentation

AwsSignatureV2::AwsSignatureV2 ( const QCryptographicHash::Algorithm  hashAlgorithm = QCryptographicHash::Sha256)

Constructs a new AwsSignatureV2 object.

Use instances of this object to provide Version 2 signatures for AWS services.

Parameters
hashAlgorithmHash algorithm for signatures. Must be either QCryptographicHash::Sha1 or QCryptographicHash::Sha256 (default, recommended).

Definition at line 51 of file awssignaturev2.cpp.

53 {
54  Q_ASSERT((hashAlgorithm == QCryptographicHash::Sha1) || (hashAlgorithm == QCryptographicHash::Sha256));
55  Q_D(AwsSignatureV2);
56  d->hashAlgorithm = hashAlgorithm;
57 }
Implements AWS Signature Version 2.
Private implementation for AwsSignatureV2.
AwsAbstractSignature()
Initialises an AwsAbstractSignature object.

Member Function Documentation

void AwsSignatureV2::sign ( const AwsAbstractCredentials credentials,
const QNetworkAccessManager::Operation  operation,
QNetworkRequest &  request,
const QByteArray &  data = QByteArray() 
) const
virtual

Sign an AWS request.

Note, credentials must be valid before calling this function. So, for example, if credentials has expired, and is refreshable, it is the caller's responsibility to refresh the credentials before calling this function.

Parameters
operationThe network operation to sign request for.
requestThe network request to be signed.
credentialsThe credentials to use for signing.
dataOptional POST / PUT data to sign request for.

Implements AwsAbstractSignature.

Definition at line 59 of file awssignaturev2.cpp.

References AwsAbstractCredentials::secretKey().

61 {
62  Q_UNUSED(data) // Not included in V2 signatures.
63  Q_D(const AwsSignatureV2);
64 
65  // Set the AccessKeyId, SignatureMethod, SignatureVersion and Timestamp query items, if not already.
66  d->adornRequest(request, credentials);
67 
68  // Calculate the signature.
69  const QByteArray stringToSign = d->canonicalRequest(operation, request.url());
70  const QString signature = QString::fromUtf8(QUrl::toPercentEncoding(QString::fromUtf8(
71  QMessageAuthenticationCode::hash(stringToSign, credentials.secretKey().toUtf8(),
72  d->hashAlgorithm).toBase64())));
73 
74  // Append the signature to the request.
75  QUrl url = request.url();
76  url.setQuery(url.query() + QLatin1String("&Signature=") + signature);
77  request.setUrl(url);
78 }
Implements AWS Signature Version 2.
int AwsSignatureV2::version ( ) const
virtual

AWS Signature version implemented by this class.

Derived classes must implement this function to report the version of the AWS Signature implemented by the class.

Returns
The AWS Signature version implemented by this class.

Implements AwsAbstractSignature.

Definition at line 80 of file awssignaturev2.cpp.

81 {
82  return 2;
83 }

The documentation for this class was generated from the following files: