Skip to content

Commit

Permalink
Add Gravatar back (still used by WordPressAuthentificator
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Jun 27, 2024
1 parent 06b0b76 commit 4f0fca5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PackageDescription

let package = Package(
name: "WordPressUI",
platforms: [.iOS(.v11)],
platforms: [.iOS(.v13)],
products: [
.library(name: "WordPressUI", targets: ["WordPressUI"]),
.library(name: "WordPressUIObjC", targets: ["WordPressUIObjC"])
Expand Down
17 changes: 16 additions & 1 deletion Sources/WordPressUI/Extensions/Gravatar/Gravatar.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import CryptoKit

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

Expand Down Expand Up @@ -146,3 +147,17 @@ public extension Gravatar {
self.canonicalURL = sanitizedURL
}
}

extension String {
func sha256() -> String {
guard let input = self.data(using: .utf8) else {
return "" // The conversion to .utf8 should never fail
}
let digest = SHA256.hash(data: input)
var output = ""
for byte in digest {
output.append(String(format: "%02x", byte))
}
return output
}
}
4 changes: 0 additions & 4 deletions Sources/WordPressUI/Extensions/UIImageView+Gravatar.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import Foundation
import UIKit

#if SWIFT_PACKAGE
import WordPressUIObjC
#endif

/// Wrapper class used to ensure removeObserver is called
private class GravatarNotificationWrapper {
let observer: NSObjectProtocol
Expand Down
4 changes: 0 additions & 4 deletions Sources/WordPressUI/Extensions/UIImageView+Networking.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import Foundation
import UIKit

#if SWIFT_PACKAGE
import WordPressUIObjC
#endif

public extension UIImageView {
enum ImageDownloadError: Error {
case noURLSpecifiedInRequest
Expand Down

0 comments on commit 4f0fca5

Please sign in to comment.