summaryrefslogtreecommitdiff
path: root/SmartDeviceLink/private/SDLSecurityQueryPayload.h
blob: 27354a47c17a04b7285f1475de7c2629c8a529a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//
//  SDLSecurityQueryPayload.h
//  SmartDeviceLink
//
//  Created by Frank Elias on 7/28/21.
//  Copyright © 2021 smartdevicelink. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "SDLRPCMessageType.h"

/// Enum for different SDL security query types
typedef NS_ENUM(Byte, SDLSecurityQueryType) {
    /// A request that will require a response
    SDLSecurityQueryTypeRequest = 0x00,

    /// A response to a request
    SDLSecurityQueryTypeResponse = 0x10,

    /// A message that does not have a response
    SDLSecurityQueryTypeNotification = 0x20,

    /// An invalid query Type
    SDLSecurityQueryTypeInvalid = 0xFF
};

/// Enum for each type of SDL security query IDs
typedef NS_ENUM(UInt32, SDLSecurityQueryId) {
    /// Send handshake data
    SDLSecurityQueryIdSendHandshake = 0x000001,

    /// Send internal error
    SDLSecurityQueryIdSendInternalError = 0x000002,

    /// Invalid query id
    SDLSecurityQueryIdInvalid = 0xFFFFFF
};

NS_ASSUME_NONNULL_BEGIN

@interface SDLSecurityQueryPayload : NSObject

/// The security query's type, could be of type request, response, or notification
@property (assign, nonatomic) SDLSecurityQueryType queryType;

/// The security query's ID.
@property (assign, nonatomic) SDLSecurityQueryId queryID;

/// 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.
@property (nullable, strong, nonatomic) NSData *jsonData;

/// The binary data that is after the header (96 bits) and the JSON data.
@property (nullable, strong, nonatomic) NSData *binaryData;

/// 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;

/// Create a security query object from security query properties
/// @param queryType The security query type to be sent
/// @param queryID The security query ID
/// @param sequenceNumber The security query sequence number
/// @param jsonData The JSON data to be set in the security query
/// @param binaryData The binary data that's after the header and the JSON data
/// @return The SDLSecurityQueryPayload non-nullable object
- (instancetype)initWithQueryType:(SDLSecurityQueryType)queryType queryID:(SDLSecurityQueryId)queryID sequenceNumber:(UInt32)sequenceNumber jsonData:(nullable NSData *)jsonData binaryData:(nullable NSData *)binaryData;

/// 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

NS_ASSUME_NONNULL_END