8

I have a concrete problem but I'm afraid it might be a duplicate or in violation of another rule, and I've been told that the SO meta is an adequate place to ask feedback on possible questions. The question would be as such:

I'm writing a small rust CLI program that prints a message to the user after they have solved a task. Normally, string literals or constants are stored in clear in a binary, so the strings command and some heuristic with grep will usually reveal whatever string the developer would like to hide.
Rust already has a tool for hiding string literals (the obfstr crate) but it only generates temporary values and my problem has to do with constants: due to its length, the message is imported from a text file via include_str! as a const. This means that i should encrypt it at the time of declaration and use a function to generate a temporary decryption at the moment of usage
Is there a Rust crate that handles compile-time obfuscation of constant strings?

Would this be answered or removed?

EDIT: After reading the feedback, I'd rephrase the question as the following:

I'm writing a small rust CLI program that asks the user to complete a task and then outputs a message (stored in a const &str). Normally, string constants in a compiled program are easily read via the strings command and I would like to obfuscate the final message at least from this casual degree of examination. The code would probably look like this:

const obfuscated_message = 
   encrypt!("This is the secret message");

fn main() {
   // User task
   let message: &str = decrypt!(obfuscated_message);
   println!("{}",message);
}

Looking for solutions to this problem, I found the obfstr crate, which works well if you only need to use the string a single time, but only works in-place and does not scale very well.
How do I define a rust const &str such that it can be used elsewhere in the program but won't appear in clear in the compiled executable?

Is this version more likely to get answered?

6
  • 9
    "Is there a Rust crate that …" This looks like a clear-cut case of asking for recommendations. You might want to generally ask how to do what you described. Commented Sep 5, 2022 at 15:15
  • Then I could reformulate it simply as "what is the best way to obfuscate a const &str?" - sorry, i wrote this while you were editing
    – none none
    Commented Sep 5, 2022 at 15:16
  • 5
    "How can I obfuscate a const &str at compile time?" is closer to the mark, but you'll still need to specify what it actually means to "obfuscate" the string. Commented Sep 5, 2022 at 15:24
  • 7
    "What is best?" is very opinionated, @nonenone . What's "best" can be very subjective, and can be defined very differently depending on your goals. For example, it might be the most performant, the shortest code, the easiest (for someone new to the language) to understand, most secure.
    – Thom A
    Commented Sep 5, 2022 at 15:24
  • 1
    I don't know Rust, but this part seems wrong to me: "Rust already has a tool for hiding string literals (the obfstr crate) but it only generates temporary values and my problem has to do with constants" How can a string literal not be a constant? Commented Sep 5, 2022 at 16:02
  • 2
    @KarlKnechtel it is, but a constant is not necessarily a literal. In the specific, the crate I'm referencing appears to only work with literals
    – none none
    Commented Sep 5, 2022 at 16:05

1 Answer 1

14

I am a regular curator of the tag and I can confirm that the question would most likely be closed as a request for an off-site resource in the current state. This has been the usual reaction to any question asking for a Rust crate.

And the truth is that "Is there a crate" is not something that is suitable to be asked here. You would search for that crate instead. Crates.io is the official registry of public Rust crates. Other resources online such as the Rust Cookbook also refer back to something on crates.io. Stack Overflow is not a good fit for keeping track of which crates solves which problem. Now, if you want to achieve a certain objective (i.e. "obfuscate some text at compile time"), then the way forward would be to ask specifically about that.

The second issue that may come around is what exactly amounts to a string being obfuscated (or even obfuscated enough for your use case), and what you have attempted so far in writing that obfuscating logic yourself. Questions of the form "I want to do X and don't know where to start" are at the risk of not having a clear direction and attracting equally vague answers.

The standard advice for questions of this kind would still be the same regardless of the programming language:

  1. pose the question as a "how to" question;
  2. and ensure that the question is clear and focused so that it can receive objective answers.

See also:

4
  • 1
    From what I've gathered I should rephrase the question along the lines of "how do I hide a const &str in such a way that it can't be read via the strings shell command?"
    – none none
    Commented Sep 5, 2022 at 15:49
  • 2
    I'm just going to leave this here: I really dislike unproductive closures. You know, the type of closures that could be avoided simply by editing the question to change a single turn of phrase into a different turn of phrase. If the only thing making the question a "resource recommendation" question is that they happened to ask, "Is there a Rust crate that...?", and you can change that to just be "How can I ...?", and you don't make that change, instead choosing to close the question, well, I think you're lazier than the author of a question that doesn't read our Help Center.
    – Cody Gray Mod
    Commented Sep 6, 2022 at 7:01
  • 2
    I also don't see this as a "how would I get started?" question. It's just a normal "how to" question. It doesn't seem subjective, it isn't asking for a tutorial, it's not asking for an off-site recommendation in the way that that close reason is intended to be used (i.e., an opinion-based recommendation, where all answers would be equally valid), and it doesn't seem problematic to me in any way except possibly that the precise meaning of "obfuscate" is not defined, which might make the question a bit too open-ended if every answerer used a different definition.
    – Cody Gray Mod
    Commented Sep 6, 2022 at 7:03
  • Related: Some meta questions on 'how-to' : Is it possible to ask general 'how to' questions? (canonical? - "Stack Overflow is a repository of "How to ..." questions ... A reasonably scoped "how to" question is the most on-topic question there can be."), How should we be advising users asking too broad or unclear how-to questions while not implying that such questions require code?, and HOW-TO questions are treated in different ways Commented Sep 6, 2022 at 9:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .