mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-26 21:35:11 +00:00
* simple_secure_chat now with a proper CLI
* new: BaseChatMesh class, for abstract chat client
This commit is contained in:
@@ -14,6 +14,25 @@ bool IdentityStore::load(const char *name, mesh::LocalIdentity& id) {
|
||||
return loaded;
|
||||
}
|
||||
|
||||
bool IdentityStore::load(const char *name, mesh::LocalIdentity& id, char display_name[], int max_name_sz) {
|
||||
bool loaded = false;
|
||||
char filename[40];
|
||||
sprintf(filename, "%s/%s.id", _dir, name);
|
||||
if (_fs->exists(filename)) {
|
||||
File file = _fs->open(filename);
|
||||
if (file) {
|
||||
loaded = id.readFrom(file);
|
||||
|
||||
int n = min(32, max_name_sz); // up to 32 bytes
|
||||
file.read((uint8_t *) display_name, n);
|
||||
display_name[n - 1] = 0; // ensure null terminator
|
||||
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
return loaded;
|
||||
}
|
||||
|
||||
bool IdentityStore::save(const char *name, const mesh::LocalIdentity& id) {
|
||||
char filename[40];
|
||||
sprintf(filename, "%s/%s.id", _dir, name);
|
||||
@@ -31,3 +50,29 @@ bool IdentityStore::save(const char *name, const mesh::LocalIdentity& id) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IdentityStore::save(const char *name, const mesh::LocalIdentity& id, const char display_name[]) {
|
||||
char filename[40];
|
||||
sprintf(filename, "%s/%s.id", _dir, name);
|
||||
|
||||
#if defined(NRF52_PLATFORM)
|
||||
File file = _fs->open(filename, FILE_O_WRITE);
|
||||
if (file) { file.seek(0); file.truncate(); }
|
||||
#else
|
||||
File file = _fs->open(filename, "w", true);
|
||||
#endif
|
||||
if (file) {
|
||||
id.writeTo(file);
|
||||
|
||||
uint8_t tmp[32];
|
||||
memset(tmp, 0, sizeof(tmp));
|
||||
int n = strlen(display_name);
|
||||
if (n > sizeof(tmp)-1) n = sizeof(tmp)-1;
|
||||
memcpy(tmp, display_name, n);
|
||||
file.write(tmp, sizeof(tmp));
|
||||
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user