diff options
author | NicoleYarroch <nicole@livio.io> | 2018-05-30 14:22:29 -0400 |
---|---|---|
committer | NicoleYarroch <nicole@livio.io> | 2018-05-30 14:22:29 -0400 |
commit | dbc9d9c163ca7f2a9351c07f7332349f9c7a2887 (patch) | |
tree | 47e1ae9d82764aa675e7d421c10b7621666c6b22 | |
parent | 09a515657aa354dcc321354c0f0657da89bd273d (diff) | |
download | sdl_ios-dbc9d9c163ca7f2a9351c07f7332349f9c7a2887.tar.gz |
Truncated the generated `SDLArtwork` filename to 16 characters.
Signed-off-by: NicoleYarroch <nicole@livio.io>
-rw-r--r-- | SmartDeviceLink/SDLArtwork.m | 5 | ||||
-rw-r--r-- | SmartDeviceLinkTests/DevAPISpecs/SDLArtworkSpec.m | 13 |
2 files changed, 17 insertions, 1 deletions
diff --git a/SmartDeviceLink/SDLArtwork.m b/SmartDeviceLink/SDLArtwork.m index bf2861b67..e5c22c2aa 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 versions 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 @@ -105,7 +107,8 @@ 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) { + // HAX: To shorten the string to 16 characters, the loop has been shortened to 8 fom 16. + for (int i = 0; i < 8; 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 |