Skip to content

Commit

Permalink
Fix data type for password (#265)
Browse files Browse the repository at this point in the history
Co-authored-by: Steve Kim <sbstevek@amazon.com>
Co-authored-by: Steve Kim <86316075+sbSteveK@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 18, 2024
1 parent 3ae634e commit 480e9e2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions Source/AwsCommonRuntimeKit/mqtt/Mqtt5Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class MqttConnectOptions: CStruct {
public let username: String?

/// Opaque binary data that the server may use for client authentication and authorization.
public let password: String?
public let password: Data?

/// A time interval, in whole seconds, that the client requests the server to persist this connection's MQTT session state for. Has no meaning if the client has not been configured to rejoin sessions. Must be non-zero in order to successfully rejoin a session. If the responding CONNACK contains a session expiry property value, then that is the negotiated session expiry value. Otherwise, the session expiry sent by the client is the negotiated value.
public let sessionExpiryInterval: TimeInterval?
Expand Down Expand Up @@ -84,7 +84,7 @@ public class MqttConnectOptions: CStruct {
public init (keepAliveInterval: TimeInterval? = nil,
clientId: String? = nil,
username: String? = nil,
password: String? = nil,
password: Data? = nil,
sessionExpiryInterval: TimeInterval? = nil,
requestResponseInformation: Bool? = nil,
requestProblemInformation: Bool? = nil,
Expand Down Expand Up @@ -176,11 +176,12 @@ public class MqttConnectOptions: CStruct {
raw_connect_options.user_property_count = userProperties!.count
raw_connect_options.user_properties = UnsafePointer<aws_mqtt5_user_property>(cUserProperties)
}
return withOptionalByteCursorPointerFromStrings(
username, password) { cUsernamePointer, cPasswordPointer in
return withOptionalByteCursorPointerFromString(username) { cUsernamePointer in
raw_connect_options.username = cUsernamePointer
raw_connect_options.password = cPasswordPointer
return body(raw_connect_options)
return withAWSByteCursorPointerFromOptionalData(to: password) { cPasswordPointer in
raw_connect_options.password = cPasswordPointer
return body(raw_connect_options)
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Test/AwsCommonRuntimeKitTests/mqtt/Mqtt5ClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ class Mqtt5ClientTests: XCBaseTestCase {
let connectOptions = MqttConnectOptions(
clientId: createClientId(),
username: inputUsername,
password: inputPassword
password: inputPassword.data(using: .utf8)
)

let clientOptions = MqttClientOptions(
Expand Down Expand Up @@ -579,7 +579,7 @@ class Mqtt5ClientTests: XCBaseTestCase {
let connectOptions = MqttConnectOptions(
clientId: createClientId(),
username: inputUsername,
password: inputPassword
password: inputPassword.data(using: .utf8)
)

let clientOptions = MqttClientOptions(
Expand Down

0 comments on commit 480e9e2

Please sign in to comment.