Files
purchases-ios/Sources/Networking/RemoteConfigBlobRefHelpers.swift
T
Rick 167d4044e3 feat(remote-config): add blob fetcher (#7115)
* 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
2026-07-02 16:20:25 +02:00

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: "")
}
}