summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank Elias <francois.elias@livio.io>2021-08-27 11:21:25 -0400
committerFrank Elias <francois.elias@livio.io>2021-08-27 11:21:25 -0400
commit415c24d2a5576eafc93652d507b171ab6220f0fb (patch)
treec035d0eccb4c51acdd0e35a2a60247a7600c00c3
parentf7d07b3532e85e2cf3024f76281d4eb48313d751 (diff)
downloadsdl_ios-415c24d2a5576eafc93652d507b171ab6220f0fb.tar.gz
comments review
-rw-r--r--SmartDeviceLink-iOS.xcodeproj/project.pbxproj16
-rw-r--r--SmartDeviceLink/private/SDLSecurityQueryPayload.h42
-rw-r--r--SmartDeviceLink/private/SDLSecurityQueryPayload.m20
-rw-r--r--SmartDeviceLinkTests/RPCSpecs/PayloadSpecs/SDLSecurityQueryPayloadSpec.m6
4 files changed, 43 insertions, 41 deletions
diff --git a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj
index c82bed27a..159e115c6 100644
--- a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj
+++ b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj
@@ -5810,16 +5810,13 @@
5D5935011A851D7E00687FB9 /* Header */ = {
isa = PBXGroup;
children = (
+ C904F1DD26D919EF00E073DA /* SecurityQuery */,
4A8BD32824F9431B000945E3 /* SDLProtocolHeader.h */,
4A8BD32924F9431B000945E3 /* SDLProtocolHeader.m */,
4A8BD32724F9431B000945E3 /* SDLV1ProtocolHeader.h */,
4A8BD32524F9431B000945E3 /* SDLV1ProtocolHeader.m */,
4A8BD32A24F9431B000945E3 /* SDLV2ProtocolHeader.h */,
4A8BD32624F9431B000945E3 /* SDLV2ProtocolHeader.m */,
- C93193DA26B1B57B008203EC /* SDLSecurityQueryPayload.h */,
- C93193DB26B1B57B008203EC /* SDLSecurityQueryPayload.m */,
- C99BE00726C53E7E00DB0B54 /* SDLSecurityQueryErrorCode.h */,
- C99BE00826C53E7E00DB0B54 /* SDLSecurityQueryErrorCode.m */,
);
name = Header;
sourceTree = "<group>";
@@ -7065,6 +7062,17 @@
name = Frameworks;
sourceTree = "<group>";
};
+ C904F1DD26D919EF00E073DA /* SecurityQuery */ = {
+ isa = PBXGroup;
+ children = (
+ C93193DA26B1B57B008203EC /* SDLSecurityQueryPayload.h */,
+ C93193DB26B1B57B008203EC /* SDLSecurityQueryPayload.m */,
+ C99BE00726C53E7E00DB0B54 /* SDLSecurityQueryErrorCode.h */,
+ C99BE00826C53E7E00DB0B54 /* SDLSecurityQueryErrorCode.m */,
+ );
+ name = SecurityQuery;
+ sourceTree = "<group>";
+ };
DA1166D71D14601C00438CEA /* Touches */ = {
isa = PBXGroup;
children = (
diff --git a/SmartDeviceLink/private/SDLSecurityQueryPayload.h b/SmartDeviceLink/private/SDLSecurityQueryPayload.h
index 3ed56bebc..ac5dd34dc 100644
--- a/SmartDeviceLink/private/SDLSecurityQueryPayload.h
+++ b/SmartDeviceLink/private/SDLSecurityQueryPayload.h
@@ -9,9 +9,7 @@
#import <Foundation/Foundation.h>
#import "SDLRPCMessageType.h"
-/**
- * Enum for different SDL security query types
- */
+/// Enum for different SDL security query types
typedef NS_ENUM(Byte, SDLSecurityQueryType) {
/// A request that will require a response
SDLSecurityQueryTypeRequest = 0x00,
@@ -23,9 +21,7 @@ typedef NS_ENUM(Byte, SDLSecurityQueryType) {
SDLSecurityQueryTypeNotification = 0x20
};
-/**
- * Enum for each type of SDL security query IDs
- */
+/// Enum for each type of SDL security query IDs
typedef NS_ENUM(NSUInteger, SDLSecurityQueryId) {
/// Send handshake data
SDLSecurityQueryIdSendHandshake = 0x000001,
@@ -38,34 +34,34 @@ NS_ASSUME_NONNULL_BEGIN
@interface SDLSecurityQueryPayload : NSObject
-/**
- The security query's type, could be of type request - response or notification
- */
+/// The security query's type, could be of type request - response or notification
@property (assign, nonatomic) SDLSecurityQueryType queryType;
-/**
- The security query's ID.
- */
+/// The security query's ID.
@property (assign, nonatomic) UInt32 queryID;
-/**
- The message ID is set by the Mobile libraries to track security messages.
- */
+/// The message ID is set by the Mobile libraries to track security messages.
@property (assign, nonatomic) UInt32 sequenceNumber;
-/**
- The JSON data following the binary query header.
- */
+/// The JSON data following the binary query header.
@property (nullable, strong, nonatomic) NSData *jsonData;
-/**
- The binary data that is after the header (96 bits) and the JSON data.
- */
+/// The binary data that is after the header (96 bits) and the JSON data.
@property (nullable, strong, nonatomic) NSData *binaryData;
-+ (nullable id)securityPayloadWithData:(NSData *)data;
+/// Create a security query object from raw data
+/// @param data The data to convert into an SDLSecurityQueryPayload object
+/// @return The SDLSecurityQueryPayload object, or nil if the data is malformed
- (nullable instancetype)initWithData:(NSData *)data;
-- (NSData *)data;
+
+/// Create a security query object from raw data
+/// @param data The data to convert into an SDLSecurityQueryPayload object
+/// @return The SDLSecurityQueryPayload object, or nil if the data is malformed
++ (nullable id)securityPayloadWithData:(NSData *)data;
+
+/// Convert the object into raw NSData
+/// @return The raw NSData of the object
+- (NSData *)convertToData;
@end
diff --git a/SmartDeviceLink/private/SDLSecurityQueryPayload.m b/SmartDeviceLink/private/SDLSecurityQueryPayload.m
index bc6520abd..e80798511 100644
--- a/SmartDeviceLink/private/SDLSecurityQueryPayload.m
+++ b/SmartDeviceLink/private/SDLSecurityQueryPayload.m
@@ -16,20 +16,14 @@ NS_ASSUME_NONNULL_BEGIN
@implementation SDLSecurityQueryPayload
-+ (nullable id)securityPayloadWithData:(NSData *)data {
- return [[SDLSecurityQueryPayload alloc] initWithData:data];
-}
-
- (nullable instancetype)initWithData:(NSData *)data {
- NSUInteger dataLength = data.length;
-
- if (data == nil || dataLength == 0) {
+ if (data == nil || data.length == 0) {
SDLLogW(@"Security Payload data is nil");
return nil;
}
- if (dataLength < SECURITY_QUERY_HEADER_SIZE) {
- SDLLogE(@"Security Payload error: not enough data to form Security Query header");
+ if (data.length < SECURITY_QUERY_HEADER_SIZE) {
+ SDLLogE(@"Security Payload error: not enough data to form Security Query header. Data length: %lu", (unsigned long)data.length);
return nil;
}
@@ -63,7 +57,7 @@ NS_ASSUME_NONNULL_BEGIN
// Extract the JSON data after the header (96 bits) based on the JSON data size
NSData *jsonData = nil;
NSUInteger offsetOfJSONData = SECURITY_QUERY_HEADER_SIZE;
- if (jsonDataSize > 0 && jsonDataSize <= dataLength - SECURITY_QUERY_HEADER_SIZE) {
+ if (jsonDataSize > 0 && jsonDataSize <= (data.length - SECURITY_QUERY_HEADER_SIZE)) {
jsonData = [data subdataWithRange:NSMakeRange(offsetOfJSONData, jsonDataSize)];
}
self.jsonData = jsonData;
@@ -85,7 +79,11 @@ NS_ASSUME_NONNULL_BEGIN
return self;
}
-- (NSData *)data {
++ (nullable id)securityPayloadWithData:(NSData *)data {
+ return [[SDLSecurityQueryPayload alloc] initWithData:data];
+}
+
+- (NSData *)convertToData {
// From the properties, create a data buffer
// Query Type - first 8 bits
// Query ID - next 24 bits
diff --git a/SmartDeviceLinkTests/RPCSpecs/PayloadSpecs/SDLSecurityQueryPayloadSpec.m b/SmartDeviceLinkTests/RPCSpecs/PayloadSpecs/SDLSecurityQueryPayloadSpec.m
index 8d19b08cf..5ebe9ce28 100644
--- a/SmartDeviceLinkTests/RPCSpecs/PayloadSpecs/SDLSecurityQueryPayloadSpec.m
+++ b/SmartDeviceLinkTests/RPCSpecs/PayloadSpecs/SDLSecurityQueryPayloadSpec.m
@@ -20,7 +20,7 @@
QuickSpecBegin(SDLSecurityQueryPayloadSpec)
__block SDLSecurityQueryPayload* testPayload;
-__block NSDictionary* dict = @{@"id": @"3", @"text":@"SDL does not support encryption"};
+__block NSDictionary* dict = @{@"id": @"3", @"text": @"SDL does not support encryption"};
NSData* (^testData)(void) = ^NSData* {
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:0 error:0];
@@ -37,7 +37,7 @@ NSData* (^testData)(void) = ^NSData* {
return data;
};
-beforeSuite(^ {
+beforeSuite(^{
testPayload = [[SDLSecurityQueryPayload alloc] init];
testPayload.queryType = 0x20;
@@ -59,7 +59,7 @@ describe(@"Getter/Setter Tests", ^ {
describe(@"Data Tests", ^ {
it(@"should convert to byte data correctly", ^ {
- expect(testPayload.data).to(equal(testData()));
+ expect(testPayload.convertToData).to(equal(testData()));
});
});