From 480e9e225f54d9e17d7ebbadbb2edde117d2e6d0 Mon Sep 17 00:00:00 2001 From: Vera Xia Date: Thu, 18 Jul 2024 10:55:10 -0700 Subject: [PATCH] Fix data type for password (#265) Co-authored-by: Steve Kim Co-authored-by: Steve Kim <86316075+sbSteveK@users.noreply.github.com> --- Source/AwsCommonRuntimeKit/mqtt/Mqtt5Options.swift | 13 +++++++------ .../mqtt/Mqtt5ClientTests.swift | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Source/AwsCommonRuntimeKit/mqtt/Mqtt5Options.swift b/Source/AwsCommonRuntimeKit/mqtt/Mqtt5Options.swift index 0f6aecc9..32104784 100644 --- a/Source/AwsCommonRuntimeKit/mqtt/Mqtt5Options.swift +++ b/Source/AwsCommonRuntimeKit/mqtt/Mqtt5Options.swift @@ -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? @@ -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, @@ -176,11 +176,12 @@ public class MqttConnectOptions: CStruct { raw_connect_options.user_property_count = userProperties!.count raw_connect_options.user_properties = UnsafePointer(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) + } } } } diff --git a/Test/AwsCommonRuntimeKitTests/mqtt/Mqtt5ClientTests.swift b/Test/AwsCommonRuntimeKitTests/mqtt/Mqtt5ClientTests.swift index 1b8781bb..38124ef8 100644 --- a/Test/AwsCommonRuntimeKitTests/mqtt/Mqtt5ClientTests.swift +++ b/Test/AwsCommonRuntimeKitTests/mqtt/Mqtt5ClientTests.swift @@ -392,7 +392,7 @@ class Mqtt5ClientTests: XCBaseTestCase { let connectOptions = MqttConnectOptions( clientId: createClientId(), username: inputUsername, - password: inputPassword + password: inputPassword.data(using: .utf8) ) let clientOptions = MqttClientOptions( @@ -579,7 +579,7 @@ class Mqtt5ClientTests: XCBaseTestCase { let connectOptions = MqttConnectOptions( clientId: createClientId(), username: inputUsername, - password: inputPassword + password: inputPassword.data(using: .utf8) ) let clientOptions = MqttClientOptions(