-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement last.fm API signature
- Loading branch information
Showing
4 changed files
with
70 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// StringMD5.swift | ||
// firstfm | ||
// | ||
// Created by Stanislas Lange on 17/07/2021. | ||
// | ||
|
||
import Foundation | ||
import CommonCrypto | ||
|
||
// Needed to compute LastFM api Signature | ||
// https://www.last.fm/api/mobileauth | ||
|
||
extension String { | ||
var md5Value: String { | ||
let length = Int(CC_MD5_DIGEST_LENGTH) | ||
var digest = [UInt8](repeating: 0, count: length) | ||
|
||
if let d = self.data(using: .utf8) { | ||
_ = d.withUnsafeBytes { body -> String in | ||
CC_MD5(body.baseAddress, CC_LONG(d.count), &digest) | ||
|
||
return "" | ||
} | ||
} | ||
|
||
return (0 ..< length).reduce("") { | ||
$0 + String(format: "%02x", digest[$1]) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters