summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Beharry <justin.beharry@livio.io>2022-08-31 12:27:39 -0400
committerJustin Beharry <justin.beharry@livio.io>2022-08-31 12:27:39 -0400
commit1e4d1204676d455c35d709f80f91ae5b8ca102b9 (patch)
treead8d97020d32ca8f2900073311cbb79d5ad36535
parent142f57e4124c4c9ba2b6a2a06cf57e5813a4620a (diff)
downloadsdl_ios-1e4d1204676d455c35d709f80f91ae5b8ca102b9.tar.gz
Create hash for SDLProtocolHeaders
-rw-r--r--SmartDeviceLink/private/SDLProtocolHeader.m11
-rw-r--r--SmartDeviceLink/private/SDLV1ProtocolHeader.m4
-rw-r--r--SmartDeviceLink/private/SDLV2ProtocolHeader.m4
3 files changed, 14 insertions, 5 deletions
diff --git a/SmartDeviceLink/private/SDLProtocolHeader.m b/SmartDeviceLink/private/SDLProtocolHeader.m
index afe93724d..dd2525c47 100644
--- a/SmartDeviceLink/private/SDLProtocolHeader.m
+++ b/SmartDeviceLink/private/SDLProtocolHeader.m
@@ -3,8 +3,10 @@
#import "SDLProtocolHeader.h"
+
#import "SDLV1ProtocolHeader.h"
#import "SDLV2ProtocolHeader.h"
+#import "SDLMacros.h"
NS_ASSUME_NONNULL_BEGIN
@@ -41,6 +43,15 @@ NS_ASSUME_NONNULL_BEGIN
return description;
}
+- (NSUInteger)hash {
+ return NSUIntRotateCell(self.data.hash, NSUIntBitCell / 2)
+ ^ NSUIntRotateCell(self.version, NSUIntBitCell / 3)
+ ^ NSUIntRotateCell(self.encrypted, NSUIntBitCell / 4)
+ ^ NSUIntRotateCell(self.frameType, NSUIntBitCell / 5)
+ ^ NSUIntRotateCell(self.frameData, NSUIntBitCell / 6)
+ ^ NSUIntRotateCell(self.sessionID, NSUIntBitCell / 7);
+}
+
+ (__kindof SDLProtocolHeader *)headerForVersion:(UInt8)version {
// VERSION DEPENDENT CODE
switch (version) {
diff --git a/SmartDeviceLink/private/SDLV1ProtocolHeader.m b/SmartDeviceLink/private/SDLV1ProtocolHeader.m
index 5cf886f91..cfbb6b1fc 100644
--- a/SmartDeviceLink/private/SDLV1ProtocolHeader.m
+++ b/SmartDeviceLink/private/SDLV1ProtocolHeader.m
@@ -84,10 +84,6 @@ NS_ASSUME_NONNULL_BEGIN
return description;
}
-- (NSUInteger)hash {
- return self.data.hash ^ self.description.hash;
-}
-
- (BOOL)isEqual:(SDLV1ProtocolHeader *)object {
return (self.hash == object.hash);
}
diff --git a/SmartDeviceLink/private/SDLV2ProtocolHeader.m b/SmartDeviceLink/private/SDLV2ProtocolHeader.m
index ca174c18c..b85dcd399 100644
--- a/SmartDeviceLink/private/SDLV2ProtocolHeader.m
+++ b/SmartDeviceLink/private/SDLV2ProtocolHeader.m
@@ -4,6 +4,8 @@
#import "SDLV2ProtocolHeader.h"
+#import "SDLMacros.h"
+
const int ProtocolV2HeaderByteSize = 12;
@@ -124,7 +126,7 @@ const int ProtocolV2HeaderByteSize = 12;
}
- (NSUInteger)hash {
- return self.data.hash ^ self.description.hash;
+ return [super hash] ^ NSUIntRotateCell(self.messageID, NSUIntBitCell / 8);
}
- (BOOL)isEqual:(SDLV2ProtocolHeader *)object {