Skip to content
This repository was archived by the owner on Jun 4, 2025. It is now read-only.

Commit 4f0fca5

Browse files
committed
Add Gravatar back (still used by WordPressAuthentificator
1 parent 06b0b76 commit 4f0fca5

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import PackageDescription
44

55
let package = Package(
66
name: "WordPressUI",
7-
platforms: [.iOS(.v11)],
7+
platforms: [.iOS(.v13)],
88
products: [
99
.library(name: "WordPressUI", targets: ["WordPressUI"]),
1010
.library(name: "WordPressUIObjC", targets: ["WordPressUIObjC"])

Sources/WordPressUI/Extensions/Gravatar/Gravatar.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Foundation
2+
import CryptoKit
23

34
/// Helper Enum that specifies all of the available Gravatar Image Ratings
45
/// TODO: Convert into a pure Swift String Enum. It's done this way to maintain ObjC Compatibility
@@ -106,7 +107,7 @@ public struct Gravatar {
106107
return email
107108
.lowercased()
108109
.trimmingCharacters(in: .whitespaces)
109-
.sha256Hash()
110+
.sha256()
110111
}
111112
}
112113

@@ -146,3 +147,17 @@ public extension Gravatar {
146147
self.canonicalURL = sanitizedURL
147148
}
148149
}
150+
151+
extension String {
152+
func sha256() -> String {
153+
guard let input = self.data(using: .utf8) else {
154+
return "" // The conversion to .utf8 should never fail
155+
}
156+
let digest = SHA256.hash(data: input)
157+
var output = ""
158+
for byte in digest {
159+
output.append(String(format: "%02x", byte))
160+
}
161+
return output
162+
}
163+
}

Sources/WordPressUI/Extensions/UIImageView+Gravatar.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import Foundation
22
import UIKit
33

4-
#if SWIFT_PACKAGE
5-
import WordPressUIObjC
6-
#endif
7-
84
/// Wrapper class used to ensure removeObserver is called
95
private class GravatarNotificationWrapper {
106
let observer: NSObjectProtocol

Sources/WordPressUI/Extensions/UIImageView+Networking.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import Foundation
22
import UIKit
33

4-
#if SWIFT_PACKAGE
5-
import WordPressUIObjC
6-
#endif
7-
84
public extension UIImageView {
95
enum ImageDownloadError: Error {
106
case noURLSpecifiedInRequest

0 commit comments

Comments
 (0)