From ae78c09c50b14a50f004b0bfc8e6a352827ac52b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konrad=20Ko=C5=82akowski?= Date: Tue, 8 Feb 2022 23:52:16 +0100 Subject: [PATCH] Added some helpers to format hashes --- DevCleaner.xcodeproj/project.pbxproj | 4 ++++ DevCleaner/Managers/Preferences.swift | 3 ++- .../Utilities/Extensions/Digest+Helpers.swift | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 DevCleaner/Utilities/Extensions/Digest+Helpers.swift diff --git a/DevCleaner.xcodeproj/project.pbxproj b/DevCleaner.xcodeproj/project.pbxproj index 9d6b619..8f9e695 100644 --- a/DevCleaner.xcodeproj/project.pbxproj +++ b/DevCleaner.xcodeproj/project.pbxproj @@ -31,6 +31,7 @@ 7162E12D209905BC00081E4E /* Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7162E12C209905BC00081E4E /* Preferences.swift */; }; 7164260C20B8903000D47EF2 /* StoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7164260B20B8903000D47EF2 /* StoreKit.framework */; }; 716667D0221A26BA004D4FC4 /* FileManager+HomeFolder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 716667CF221A26BA004D4FC4 /* FileManager+HomeFolder.swift */; }; + 7169D2B027B32A8E00882E03 /* Digest+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7169D2AF27B32A8E00882E03 /* Digest+Helpers.swift */; }; 717A9F1B22DBAF9300682A0A /* OldDocumentationFileEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 717A9F1A22DBAF9300682A0A /* OldDocumentationFileEntry.swift */; }; 717AB6B620C71F4D0096743C /* LoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 717AB6B520C71F4D0096743C /* LoadingView.swift */; }; 717FC51725B4DABD00FA93EB /* InterfacePreviewsFileEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 717FC51625B4DABD00FA93EB /* InterfacePreviewsFileEntry.swift */; }; @@ -85,6 +86,7 @@ 7164260420ACE2EC00D47EF2 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 7164260B20B8903000D47EF2 /* StoreKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = StoreKit.framework; path = System/Library/Frameworks/StoreKit.framework; sourceTree = SDKROOT; }; 716667CF221A26BA004D4FC4 /* FileManager+HomeFolder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FileManager+HomeFolder.swift"; sourceTree = ""; }; + 7169D2AF27B32A8E00882E03 /* Digest+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Digest+Helpers.swift"; sourceTree = ""; }; 717A9F1A22DBAF9300682A0A /* OldDocumentationFileEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OldDocumentationFileEntry.swift; sourceTree = ""; }; 717AB6B520C71F4D0096743C /* LoadingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingView.swift; sourceTree = ""; }; 717FC51625B4DABD00FA93EB /* InterfacePreviewsFileEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InterfacePreviewsFileEntry.swift; sourceTree = ""; }; @@ -282,6 +284,7 @@ 716667CF221A26BA004D4FC4 /* FileManager+HomeFolder.swift */, 71AE37EE23776AFB009C03BB /* FileManager+DateProperties.swift */, 71E7F835214E8D4400A11601 /* URL+AcquireAccessFromSandbox.swift */, + 7169D2AF27B32A8E00882E03 /* Digest+Helpers.swift */, ); path = Extensions; sourceTree = ""; @@ -457,6 +460,7 @@ 717FC51725B4DABD00FA93EB /* InterfacePreviewsFileEntry.swift in Sources */, 7100BEE322F6E771002E82B2 /* Profiler.swift in Sources */, 71A21A0C20541BE800B55651 /* XcodeFiles.swift in Sources */, + 7169D2B027B32A8E00882E03 /* Digest+Helpers.swift in Sources */, 7140B61F2323E1F7005768A7 /* HelpViewController.swift in Sources */, 717AB6B620C71F4D0096743C /* LoadingView.swift in Sources */, 712F999E20D65229003927BC /* Donations.swift in Sources */, diff --git a/DevCleaner/Managers/Preferences.swift b/DevCleaner/Managers/Preferences.swift index aa8113f..f9e1eec 100644 --- a/DevCleaner/Managers/Preferences.swift +++ b/DevCleaner/Managers/Preferences.swift @@ -42,7 +42,8 @@ public final class Preferences { fileprivate static func folderBookmarkKey(for url: URL) -> String { let urlStringData = Data(url.path.utf8) let sha256hash = SHA256.hash(data: urlStringData) - return "DCFolderBookmark_\(sha256hash.description)" + + return "DCFolderBookmark_\(sha256hash.hexStr)" } } diff --git a/DevCleaner/Utilities/Extensions/Digest+Helpers.swift b/DevCleaner/Utilities/Extensions/Digest+Helpers.swift new file mode 100644 index 0000000..58c6e0c --- /dev/null +++ b/DevCleaner/Utilities/Extensions/Digest+Helpers.swift @@ -0,0 +1,19 @@ +// +// Digest+Helpers.swift +// DevCleaner +// +// Created by Konrad Kołakowski on 08/02/2022. +// Copyright © 2022 One Minute Games. All rights reserved. +// + +import Foundation +import CryptoKit + +extension Digest { + public var bytes: [UInt8] { Array(makeIterator()) } + public var data: Data { Data(bytes) } + + public var hexStr: String { + bytes.map { String(format: "%02X", $0) }.joined() + } +}