lib/arkana/templates/kotlin/arkana.kt.erb
<% require_relative "lib/arkana/helpers/string" %>
<% require_relative "lib/arkana/helpers/kotlin_template_helper" %>
<% # TODO: Sort these import statements alphabetically %>
// DO NOT MODIFY
// Automatically generated by Arkana (https://github.com/rogerluan/arkana)
package <%= @kotlin_package_name %>
object <%= @namespace %> {
private val salt = listOf(<%= @salt.formatted %>)
internal fun decode(encoded: List<Int>, cipher: List<Int>): String {
val decoded = encoded.mapIndexed { index, item ->
(item xor cipher[(index % cipher.size)]).toByte()
}.toByteArray()
return decoded.toString(Charsets.UTF_8)
}
internal fun decodeInt(encoded: List<Int>, cipher: List<Int>): Int {
return decode(encoded = encoded, cipher = cipher).toInt()
}
internal fun decodeBoolean(encoded: List<Int>, cipher: List<Int>): Boolean {
return decode(encoded = encoded, cipher = cipher).toBoolean()
}
object Global {
<% @global_secrets.each_with_index do |secret, index| %>
val <%= secret.key.camel_case %>: <%= KotlinTemplateHelper.kotlin_type(secret.type) %>
get() {
val encoded = listOf(<%= secret.encoded_value %>)
return <%= KotlinTemplateHelper.kotlin_decode_function(secret.type) %>(encoded = encoded, cipher = salt)
}
<% unless index == @global_secrets.length - 1 %>
<% end %>
<% end %>
}
<% @environments.each_with_index do |environment, env_index| %>
object <%= environment %> : <%= @namespace %>Environment {
<% environment_protocol_secrets(environment).each_with_index do |secret, secret_index| %>
override val <%= secret.protocol_key.camel_case %>: <%= KotlinTemplateHelper.kotlin_type(secret.type) %>
get() {
val encoded = listOf(<%= secret.encoded_value %>)
return <%= KotlinTemplateHelper.kotlin_decode_function(secret.type) %>(encoded = encoded, cipher = salt)
}
<% unless secret_index == environment_protocol_secrets(environment).length - 1 %>
<% end %>
<% end %>
}
<% unless env_index == @environments.length - 1 %>
<% end %>
<% end %>
}