mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
37 lines
972 B
Plaintext
37 lines
972 B
Plaintext
// Secrets.swift.gyb
|
|
%{
|
|
import os
|
|
|
|
def chunks(seq, size):
|
|
return (seq[i:(i + size)] for i in range(0, len(seq), size))
|
|
|
|
def encode(string, salt):
|
|
bytes = string.encode("UTF-8")
|
|
return [ord(bytes[i]) ^ salt[i % len(salt)] for i in range(0, len(bytes))]
|
|
|
|
salt = [ord(byte) for byte in os.urandom(64)]
|
|
}%
|
|
enum Secrets {
|
|
|
|
static var FeedWranglerClientKey: String {
|
|
let encoded: [UInt8] = [
|
|
% for chunk in chunks(encode(os.environ.get('FEED_WRANGLER_KEY'), salt), 8):
|
|
${"".join(["0x%02x, " % byte for byte in chunk])}
|
|
% end
|
|
]
|
|
|
|
return decode(encoded, salt: salt)
|
|
}
|
|
|
|
private static let salt: [UInt8] = [
|
|
% for chunk in chunks(salt, 8):
|
|
${"".join(["0x%02x, " % byte for byte in chunk])}
|
|
% end
|
|
]
|
|
|
|
private static func decode(_ encoded: [UInt8], salt: [UInt8]) -> String {
|
|
String(decoding: encoded.enumerated().map { (offset, element) in
|
|
element ^ salt[offset % salt.count]
|
|
}, as: UTF8.self)
|
|
}
|
|
} |