MCPcopy Create free account
hub / github.com/AGWA/git-crypt / validate_key_name

Function validate_key_name

key.cpp:311–335  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

309}
310
311bool validate_key_name (const char* key_name, std::string* reason)
312{
313 if (!*key_name) {
314 if (reason) { *reason = "Key name may not be empty"; }
315 return false;
316 }
317
318 if (std::strcmp(key_name, "default") == 0) {
319 if (reason) { *reason = "`default' is not a legal key name"; }
320 return false;
321 }
322 // Need to be restrictive with key names because they're used as part of a Git filter name
323 size_t len = 0;
324 while (char c = *key_name++) {
325 if (!std::isalnum(c) && c != '-' && c != '_') {
326 if (reason) { *reason = "Key names may contain only A-Z, a-z, 0-9, '-', and '_'"; }
327 return false;
328 }
329 if (++len > KEY_NAME_MAX_LEN) {
330 if (reason) { *reason = "Key name is too long"; }
331 return false;
332 }
333 }
334 return true;
335}
336

Callers 3

load_headerMethod · 0.85
decrypt_repo_keysFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected