Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Fix indentation of code after modularization #1698

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,82 +14,79 @@ import protocol SmithyHTTPAuthAPI.Signer
import struct Smithy.Attributes
import struct Smithy.AttributeKey

// Code left indented to prevent Git diff from being blown up by whitespace changes.
// Will fix after event stream modularizaion has been reviewed.
/// Signs a `Message` using the AWS SigV4 signing algorithm
public class AWSMessageSigner: MessageSigner {
let encoder: MessageEncoder
let signer: () async throws -> MessageDataSigner
let signingConfig: () async throws -> AWSSigningConfig
let requestSignature: () -> String
// Attribute key used to save AWSSigningConfig into signingProperties argument
// for AWSSigV4Signer::signEvent call that conforms to Signer::signEvent.
static let signingConfigKey = AttributeKey<AWSSigningConfig>(name: "EventStreamSigningConfig")

/// Signs a `Message` using the AWS SigV4 signing algorithm
public class AWSMessageSigner: MessageSigner {
let encoder: MessageEncoder
let signer: () async throws -> MessageDataSigner
let signingConfig: () async throws -> AWSSigningConfig
let requestSignature: () -> String
// Attribute key used to save AWSSigningConfig into signingProperties argument
// for AWSSigV4Signer::signEvent call that conforms to Signer::signEvent.
static let signingConfigKey = AttributeKey<AWSSigningConfig>(name: "EventStreamSigningConfig")

private var _previousSignature: String?
private var _previousSignature: String?

/// Returns the previous signature used to sign a message
/// If no previous signature is available, then the request signature returned
/// which acts as previous signature for the first message
var previousSignature: String {
get {
if let signature = _previousSignature {
return signature
}

let requestSignature = requestSignature()
_previousSignature = requestSignature
return requestSignature
}
set {
_previousSignature = newValue
/// Returns the previous signature used to sign a message
/// If no previous signature is available, then the request signature returned
/// which acts as previous signature for the first message
var previousSignature: String {
get {
if let signature = _previousSignature {
return signature
}
}

public init(encoder: MessageEncoder,
signer: @escaping () async throws -> MessageDataSigner,
signingConfig: @escaping () async throws -> AWSSigningConfig,
requestSignature: @escaping () -> String) {
self.encoder = encoder
self.signer = signer
self.signingConfig = signingConfig
self.requestSignature = requestSignature
let requestSignature = requestSignature()
_previousSignature = requestSignature
return requestSignature
}

/// Signs a `Message` using the AWS SigV4 signing algorithm
/// - Parameter message: `Message` to sign
/// - Returns: Signed `Message` with `:chunk-signature` & `:date` headers
public func sign(message: Message) async throws -> Message {
// encode to bytes
let encodedMessage = try encoder.encode(message: message)
let signingConfig = try await self.signingConfig()
// Fetch signer
let signer = try await self.signer()
// Wrap config into signingProperties: Attributes
var configWrapper = Attributes()
configWrapper.set(key: AWSMessageSigner.signingConfigKey, value: signingConfig)
// Sign encoded bytes
let signingResult = try await signer.signEvent(payload: encodedMessage,
previousSignature: previousSignature,
signingProperties: configWrapper)
previousSignature = signingResult.signature
return signingResult.output
set {
_previousSignature = newValue
}
}

/// Signs an empty `Message` using the AWS SigV4 signing algorithm
/// - Returns: Signed `Message` with `:chunk-signature` & `:date` headers
public func signEmpty() async throws -> Message {
let signingConfig = try await self.signingConfig()
// Fetch signer
let signer = try await self.signer()
// Wrap config into signingProperties: Attributes
var configWrapper = Attributes()
configWrapper.set(key: AWSMessageSigner.signingConfigKey, value: signingConfig)
// Sign empty payload
let signingResult = try await signer.signEvent(payload: .init(),
previousSignature: previousSignature,
signingProperties: configWrapper)
return signingResult.output
}
public init(encoder: MessageEncoder,
signer: @escaping () async throws -> MessageDataSigner,
signingConfig: @escaping () async throws -> AWSSigningConfig,
requestSignature: @escaping () -> String) {
self.encoder = encoder
self.signer = signer
self.signingConfig = signingConfig
self.requestSignature = requestSignature
}

/// Signs a `Message` using the AWS SigV4 signing algorithm
/// - Parameter message: `Message` to sign
/// - Returns: Signed `Message` with `:chunk-signature` & `:date` headers
public func sign(message: Message) async throws -> Message {
// encode to bytes
let encodedMessage = try encoder.encode(message: message)
let signingConfig = try await self.signingConfig()
// Fetch signer
let signer = try await self.signer()
// Wrap config into signingProperties: Attributes
var configWrapper = Attributes()
configWrapper.set(key: AWSMessageSigner.signingConfigKey, value: signingConfig)
// Sign encoded bytes
let signingResult = try await signer.signEvent(payload: encodedMessage,
previousSignature: previousSignature,
signingProperties: configWrapper)
previousSignature = signingResult.signature
return signingResult.output
}

/// Signs an empty `Message` using the AWS SigV4 signing algorithm
/// - Returns: Signed `Message` with `:chunk-signature` & `:date` headers
public func signEmpty() async throws -> Message {
let signingConfig = try await self.signingConfig()
// Fetch signer
let signer = try await self.signer()
// Wrap config into signingProperties: Attributes
var configWrapper = Attributes()
configWrapper.set(key: AWSMessageSigner.signingConfigKey, value: signingConfig)
// Sign empty payload
let signingResult = try await signer.signEvent(payload: .init(),
previousSignature: previousSignature,
signingProperties: configWrapper)
return signingResult.output
}
}
Loading