summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2018-05-31 16:59:07 -0400
committerGitHub <noreply@github.com>2018-05-31 16:59:07 -0400
commita439a09d0d2a0a5a840cdf9679321fec23d90520 (patch)
treef89bfe4e4d12ca95083bfd256e645d85c610af8e
parent09a515657aa354dcc321354c0f0657da89bd273d (diff)
parent0d35a6cd954fb2518118bd8093c117fc4d3250da (diff)
downloadsdl_ios-a439a09d0d2a0a5a840cdf9679321fec23d90520.tar.gz
Merge pull request #985 from smartdevicelink/bug/issue_976_generated_SDLArtwork_name_too_long
Truncated the generated `SDLArtwork` filename to 16 characters
-rw-r--r--SmartDeviceLink/SDLArtwork.m7
-rw-r--r--SmartDeviceLinkTests/DevAPISpecs/SDLArtworkSpec.m13
2 files changed, 18 insertions, 2 deletions
diff --git a/SmartDeviceLink/SDLArtwork.m b/SmartDeviceLink/SDLArtwork.m
index bf2861b67..dd0545616 100644
--- a/SmartDeviceLink/SDLArtwork.m
+++ b/SmartDeviceLink/SDLArtwork.m
@@ -94,6 +94,8 @@ NS_ASSUME_NONNULL_BEGIN
/**
* Creates a string representation of NSData by hashing the data using the MD5 hash function. This string is not guaranteed to be unique as collisions can occur, however collisions are extremely rare.
*
+ * HAX: A MD5 hash always creates a string with 32 characters (128-bits). Due to some implementations of Core not following the spec, file names that are too long are being rejected. To try to accommodate this setup, hashed file names are being truncated to 16 characters.
+ *
* Sourced from https://stackoverflow.com/questions/2018550/how-do-i-create-an-md5-hash-of-a-string-in-cocoa
*
* @param data The data to hash
@@ -104,8 +106,9 @@ NS_ASSUME_NONNULL_BEGIN
unsigned char hash[CC_MD5_DIGEST_LENGTH];
CC_MD5([data bytes], (CC_LONG)[data length], hash);
- NSMutableString *formattedHash = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
- for (int i = 0; i < CC_MD5_DIGEST_LENGTH; i += 1) {
+ NSMutableString *formattedHash = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH];
+ // HAX: To shorten the string to 16 characters, the loop has been shortened to 8 fom 16.
+ for (int i = 0; i < CC_MD5_DIGEST_LENGTH / 2; i += 1) {
[formattedHash appendFormat:@"%02x", hash[i]];
}
return formattedHash;
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLArtworkSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLArtworkSpec.m
index f6fba3240..8e787411d 100644
--- a/SmartDeviceLinkTests/DevAPISpecs/SDLArtworkSpec.m
+++ b/SmartDeviceLinkTests/DevAPISpecs/SDLArtworkSpec.m
@@ -146,6 +146,19 @@ describe(@"SDLArtwork", ^{
expect(expectedName1).toNot(equal(expectedName2));
});
});
+
+ context(@"If generating a name for the artwork using the md5 hash", ^{
+ __block NSString *expectedName = nil;
+
+ beforeEach(^{
+ expectedName = nil;
+ });
+
+ it(@"should be truncated to 16 characters", ^{
+ expectedName = [SDLArtwork sdl_md5HashFromNSData:UIImagePNGRepresentation(testImagePNG)];
+ expect(expectedName.length).to(equal(16));
+ });
+ });
});
QuickSpecEnd