From aff67ceda804fb0f52f7879ed85fc36ef3655b1d Mon Sep 17 00:00:00 2001 From: Nate Weaver Date: Fri, 1 May 2020 19:23:58 -0500 Subject: [PATCH] Add documentation comments; don't return an optional from the FileHandle method --- generate_appcast/URL+Hashing.swift | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/generate_appcast/URL+Hashing.swift b/generate_appcast/URL+Hashing.swift index 9e2bc789..9f18532d 100644 --- a/generate_appcast/URL+Hashing.swift +++ b/generate_appcast/URL+Hashing.swift @@ -11,7 +11,11 @@ import CommonCrypto extension FileHandle { - func sha256String() -> String? { + /// Calculate the SHA-256 hash of the file referenced by the file handle. + /// + /// - Returns: The SHA-256 hash of the file (as a hexadecimal string). + func sha256String() -> String { + // This uses CommonCrypto instead of CryptoKit so it can work on macOS < 10.15 var context = CC_SHA256_CTX() CC_SHA256_Init(&context) @@ -36,7 +40,12 @@ extension FileHandle { extension URL { + /// Calculates the SHA-256 hash of the file referened by the URL. + /// + /// - Returns: The SHA-256 hash of the file (as a hexadecimal string), or `nil` if + /// the URL doesn't point to a file. func sha256String() -> String? { + guard self.isFileURL else { return nil } guard let filehandle = try? FileHandle(forReadingFrom: self) else { return nil } return filehandle.sha256String()