Secrets are never printed
Programs often write passwords, tokens and API keys to a log file by mistake. In Novis you declare them as
secret string:
<?nvs// This program checks an API key without printing it.secret string $key = 'sk-12345';
// `==` works on a secret string. The result is a plain `bool`.echo $key == 'sk-12345' ? 'key accepted' : 'key rejected', "\n";
// A string built from a secret string is secret too. `echo $header` does not compile.secret string $header = 'Bearer ' . $key;echo $header == 'Bearer sk-12345' ? 'header ready' : 'header wrong', "\n";key acceptedheader readyYou can compare a secret string, and you can build a new string from it. The new string is secret too.
A type test with is also gives a secret value.
Printing a secret string does not compile:
<?nvs// This program prints a secret string, so it does not compile.secret string $key = 'sk-12345';echo $key, "\n";error[E0790]: `echo` cannot print a `secret` value --> secret-values-error.nvs:4:6 |4 | echo $key, "\n"; | ^^^^ this value is `secret` = help: Output is read by people and saved in logs. To print the value anyway, call `Core\Secret::reveal($value, "reason")` first. Joining it into a longer string does not help. The result is `secret` too.
error: aborting due to 1 errorTo read what a code means and how to fix it, run `nvs agent show <code>`.The same is true for an error message, a debug dump and JSON output. Core\Secret::reveal gives a
plain string when you really need one. You write the reason as its second argument.
Read more in Syntax: tainted and secret strings.
