-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an option for disabling encryption for a cache file name #1140
Conversation
@hasan-monument Thanks for it. The change looks good, but may I know what's the use case of it? The cache folder is visible to your users and storing the files with hashed names would protect privacy, that is especially important when you are trying save files with some personal information (like ID or names) in the URLs. |
I was storing images like My suggestion is you should give an option to developers for that. Kingfisher also has the resource This is just my suggestion, I respect your decision. Thanks for the review. |
Sources/Cache/DiskStorage.swift
Outdated
@@ -310,6 +317,9 @@ extension DiskStorage { | |||
/// Default is `nil`, means that the cache file does not contain a file extension. | |||
public var pathExtension: String? = nil | |||
|
|||
/// Default is `true`, means that md5 encryption will be used for creation the cache file name. | |||
public var useEncryptionForCacheFileName: Bool = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public var useEncryptionForCacheFileName: Bool = true | |
public var usesHashedFileName = true |
Sources/Cache/DiskStorage.swift
Outdated
@@ -310,6 +317,9 @@ extension DiskStorage { | |||
/// Default is `nil`, means that the cache file does not contain a file extension. | |||
public var pathExtension: String? = nil | |||
|
|||
/// Default is `true`, means that md5 encryption will be used for creation the cache file name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Default is `true`, means that md5 encryption will be used for creation the cache file name. | |
/// Default is `true`, means that the cache file name will be hashed before storing. |
Sources/Cache/DiskStorage.swift
Outdated
let hashedKey = key.kf.md5 | ||
if let ext = config.pathExtension { | ||
return "\(hashedKey).\(ext)" | ||
if self.config.useEncryptionForCacheFileName { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if self.config.useEncryptionForCacheFileName { | |
if self.config.usesHashedFileName { |
@hasan-monument Thanks for the explaination. I understood your case and I agree that we can provide an option for it. May I ask you to change the name to And it would be great if you can also add some tests for this property too. After that, we can merge and release a new version for it. Thank you! |
I didn't add a test case for validation md5 string, because I didn't want to import the library |
Let’s add it. May you can use kf.md5 from this https://github.com/onevcat/Kingfisher/blob/master/Sources/Utility/String%2BMD5.swift to avoid introducing the library importing. |
Thanks for the hint. Added. |
Add an option for disabling encryption for a cache file name
This option allows disabling md5 encryption for creation cache file name in DiskStorage.