mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-11 22:55:55 +05:45
* feat(remote-config): add blob fetcher * fix(remote-config): retry blob fetches with next source * docs(remote-config): document blob fetch scheduler * fix(remote-config): coalesce direct blob fetches * fix(remote-config): avoid failing over on missing blobs * refactor(remote-config): simplify blob fetcher API * fix(remote-config): clarify exhausted blob source log * refactor(remote-config): loosen blob fetcher protocol constraint * fix(remote-config): synchronize blob store access * fix(remote-config): avoid source failover on cancelled blob downloads
47 lines
1.2 KiB
Swift
47 lines
1.2 KiB
Swift
//
|
|
// RemoteConfigBlobRefHelpers.swift
|
|
// RevenueCat
|
|
//
|
|
// Created by Rick van der Linden.
|
|
// Copyright © 2026 RevenueCat, Inc. All rights reserved.
|
|
|
|
import CryptoKit
|
|
import Foundation
|
|
|
|
enum RemoteConfigBlobRefHelpers {
|
|
|
|
static func isValid(_ ref: String) -> Bool {
|
|
return ref.range(of: Self.validRefPattern, options: .regularExpression) != nil
|
|
}
|
|
|
|
static func ref(for bytes: UnsafeRawBufferPointer) -> String {
|
|
var hash = SHA256()
|
|
hash.update(bufferPointer: bytes)
|
|
|
|
return Self.base64URLString(from: Array(hash.finalize().prefix(Self.checksumSize)))
|
|
}
|
|
|
|
static func isValidPayload(
|
|
_ bytes: UnsafeRawBufferPointer,
|
|
expectedRef ref: String
|
|
) -> Bool {
|
|
return self.isValid(ref) && self.ref(for: bytes) == ref
|
|
}
|
|
|
|
}
|
|
|
|
private extension RemoteConfigBlobRefHelpers {
|
|
|
|
static let checksumSize = 24
|
|
static let validRefPattern = #"^[A-Za-z0-9_-]{32}$"#
|
|
|
|
static func base64URLString(from bytes: [UInt8]) -> String {
|
|
return Data(bytes)
|
|
.base64EncodedString()
|
|
.replacingOccurrences(of: "+", with: "-")
|
|
.replacingOccurrences(of: "/", with: "_")
|
|
.replacingOccurrences(of: "=", with: "")
|
|
}
|
|
|
|
}
|