File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2222 return [url absoluteString ];
2323}
2424static inline NSString *cachePathForKey (NSString *key) {
25- NSString *fileName = [NSString stringWithFormat: @" JMImageCache-%u " , [key hash ]];
25+ NSString *fileName = [NSString stringWithFormat: @" JMImageCache-%@ " , [JMImageCache SHA1FromString: key ]];
2626 return [JMImageCacheDirectory () stringByAppendingPathComponent: fileName];
2727}
2828
@@ -262,4 +262,25 @@ - (void) performDiskWriteOperation:(NSInvocation *)invoction {
262262 [self .diskOperationQueue addOperation: operation];
263263}
264264
265+ #pragma mark - Hash methods
266+
267+ + (NSString *)SHA1FromString : (NSString *)string
268+ {
269+ unsigned char digest[CC_SHA1_DIGEST_LENGTH ];
270+
271+ NSData *stringBytes = [string dataUsingEncoding: NSUTF8StringEncoding];
272+
273+ if (CC_SHA1 ([stringBytes bytes ], (CC_LONG )[stringBytes length ], digest)) {
274+
275+ NSMutableString *output = [NSMutableString stringWithCapacity: CC_SHA1_DIGEST_LENGTH * 2 ];
276+
277+ for (int i = 0 ; i < CC_SHA1_DIGEST_LENGTH ; i++) {
278+ [output appendFormat: @" %02x " , digest[i]];
279+ }
280+
281+ return output;
282+ }
283+ return nil ;
284+ }
285+
265286@end
You can’t perform that action at this time.
0 commit comments