mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2024-12-27 18:12:30 +01:00
53 lines
1.5 KiB
Plaintext
53 lines
1.5 KiB
Plaintext
// Generated by Secrets.swift.gyb
|
|
%{
|
|
import os
|
|
|
|
secrets = ['FEED_WRANGLER_KEY', 'MERCURY_CLIENT_ID', 'MERCURY_CLIENT_SECRET', 'FEEDLY_CLIENT_ID', 'FEEDLY_CLIENT_SECRET', 'TWITTER_CONSUMER_KEY', 'TWITTER_CONSUMER_SECRET', 'REDDIT_CONSUMER_KEY', 'INOREADER_APP_ID', 'INOREADER_APP_KEY']
|
|
|
|
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))]
|
|
|
|
def snake_to_camel(snake_str):
|
|
components = snake_str.split('_')
|
|
return components[0].lower() + ''.join(x.title() for x in components[1:])
|
|
|
|
salt = [ord(byte) for byte in os.urandom(64)]
|
|
}%
|
|
import Secrets
|
|
|
|
public struct Secrets: SecretsProvider {
|
|
% for secret in secrets:
|
|
|
|
public var ${snake_to_camel(secret)}: String {
|
|
let encoded: [UInt8] = [
|
|
% for chunk in chunks(encode(os.environ.get(secret) or "", salt), 8):
|
|
${"".join(["0x%02x, " % byte for byte in chunk])}
|
|
% end
|
|
]
|
|
|
|
return decode(encoded, salt: salt)
|
|
}
|
|
% end
|
|
|
|
%{
|
|
# custom example: static let myVariable = "${os.environ.get('MY_CUSTOM_VARIABLE')}"
|
|
}%
|
|
|
|
private let salt: [UInt8] = [
|
|
% for chunk in chunks(salt, 8):
|
|
${"".join(["0x%02x, " % byte for byte in chunk])}
|
|
% end
|
|
]
|
|
|
|
private func decode(_ encoded: [UInt8], salt: [UInt8]) -> String {
|
|
String(decoding: encoded.enumerated().map { (offset, element) in
|
|
element ^ salt[offset % salt.count]
|
|
}, as: UTF8.self)
|
|
}
|
|
|
|
}
|