X-Git-Url: https://git.mdrn.pl/wl-app.git/blobdiff_plain/53b27422d140022594fc241cca91c3183be57bca..48b2fe9f7c2dc3d9aeaaa6dbfb27c7da4f3235ff:/iOS/Pods/OAuthSwift/Sources/HMAC.swift diff --git a/iOS/Pods/OAuthSwift/Sources/HMAC.swift b/iOS/Pods/OAuthSwift/Sources/HMAC.swift new file mode 100644 index 0000000..27b13c5 --- /dev/null +++ b/iOS/Pods/OAuthSwift/Sources/HMAC.swift @@ -0,0 +1,55 @@ +// +// HMAC.swift +// OAuthSwift +// +// Created by Dongri Jin on 1/28/15. +// Copyright (c) 2015 Dongri Jin. All rights reserved. +// + +import Foundation + +open class HMAC { + + let key: [UInt8] = [] + + class internal func sha1(key: Data, message: Data) -> Data? { + let blockSize = 64 + var key = key.bytes + let message = message.bytes + + if key.count > blockSize { + key = SHA1(key).calculate() + } else if key.count < blockSize { // padding + key += [UInt8](repeating: 0, count: blockSize - key.count) + } + + var ipad = [UInt8](repeating: 0x36, count: blockSize) + for idx in key.indices { + ipad[idx] = key[idx] ^ ipad[idx] + } + + var opad = [UInt8](repeating: 0x5c, count: blockSize) + for idx in key.indices { + opad[idx] = key[idx] ^ opad[idx] + } + + let ipadAndMessageHash = SHA1(ipad + message).calculate() + let mac = SHA1(opad + ipadAndMessageHash).calculate() + + return Data(bytes: UnsafePointer(mac), count: mac.count) + + } + +} + +extension HMAC: OAuthSwiftSignatureDelegate { + open static func sign(hashMethod: OAuthSwiftHashMethod, key: Data, message: Data) -> Data? { + switch hashMethod { + case .sha1: + return sha1(key: key, message: message) + case .none: + assertionFailure("Must no sign with none") + return nil + } + } +}