/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
using System;
using System.Text;
namespace Amazon.Runtime.Internal.Auth
{
///
/// Encapsulates the various fields and eventual signing value that makes up
/// an AWS4a signature. This can be used to retrieve the required authorization string
/// or authorization query parameters for the final request as well as hold ongoing
/// signature computations for subsequent calls related to the initial signing.
///
public class AWS4aSigningResult : AWSSigningResultBase
{
private readonly string _regionSet;
private readonly string _signature;
private readonly string _service;
private readonly string _presignedUri;
private readonly ImmutableCredentials _credentials;
///
/// Constructs a new signing result instance for a computed signature
///
/// The access key that was included in the signature
/// Date/time (UTC) that the signature was computed
/// The collection of headers names that were included in the signature
/// Formatted 'scope' value for signing (YYYYMMDD/region/service/aws4_request)
/// The set of AWS regions this signature is valid for
/// Computed signature
/// Service the request was signed for
/// Presigned Uri
/// Credentials of the AWS account making the signed request
public AWS4aSigningResult(string awsAccessKeyId,
DateTime signedAt,
string signedHeaders,
string scope,
string regionSet,
string signature,
string service,
string presignedUri,
ImmutableCredentials credentials) :
base(awsAccessKeyId, signedAt, signedHeaders, scope)
{
_regionSet = regionSet;
_signature = signature;
_service = service;
_presignedUri = presignedUri;
_credentials = credentials;
}
///
/// Returns the hex string representing the signature
///
public override string Signature
{
get { return _signature; }
}
///
/// Returns the signature in a form usable as an 'Authorization' header value.
///
public override string ForAuthorizationHeader
{
get
{
var authorizationHeader = new StringBuilder()
.Append(AWS4Signer.AWS4aAlgorithmTag)
.AppendFormat(" {0}={1}/{2},", AWS4Signer.Credential, AccessKeyId, Scope)
.AppendFormat(" {0}={1},", AWS4Signer.SignedHeaders, SignedHeaders)
.AppendFormat(" {0}={1}", AWS4Signer.Signature, Signature);
return authorizationHeader.ToString();
}
}
///
/// Returns the set of regions this signature is valid for
///
public string RegionSet
{
get { return _regionSet; }
}
///
/// Returns the full presigned Uri
///
public string PresignedUri
{
get { return _presignedUri; }
}
///
/// Returns the service the request was signed for
///
public string Service
{
get { return _service; }
}
///
/// Returns the credentials of the AWS account making the signed request
///
public ImmutableCredentials Credentials
{
get { return _credentials; }
}
}
}