salt_password does nothing with class state so move it out

This commit is contained in:
psykose 2024-10-16 05:38:01 +02:00
parent 9f33247d32
commit b18c8820a2

View file

@ -1,3 +1,21 @@
static void salt_password (string password, out string token, out string salt) {
const int SALT_BYTES = 8;
uchar salt_bytes[SALT_BYTES];
GCrypt.Random.randomize (salt_bytes);
uchar salt_chars[2*SALT_BYTES+1];
for (int i = 0; i < SALT_BYTES; i += 1) {
salt_chars[2*i+0] = "0123456789abcdef"[(salt_bytes[i]>>4)&0xf];
salt_chars[2*i+1] = "0123456789abcdef"[(salt_bytes[i]>>0)&0xf];
}
salt_chars[2*SALT_BYTES] = 0;
var checksum = new Checksum (ChecksumType.MD5);
checksum.update ((uchar[]) password, -1);
checksum.update (salt_chars, -1);
token = checksum.get_string ();
salt = (string) salt_chars;
}
[GtkTemplate (ui = "/eu/callcc/audrey/ui/setup.ui")]
public class Ui.Setup : Adw.PreferencesDialog {
public string status { get; private set; default = _("Not connected"); }
@ -30,7 +48,7 @@ public class Ui.Setup : Adw.PreferencesDialog {
this.status = _("Connecting...");
string new_token, new_salt;
this.salt_password (this.password, out new_token, out new_salt);
salt_password (this.password, out new_token, out new_salt);
var api = new Subsonic.with_token (
this.server_url,
this.username,
@ -99,24 +117,6 @@ public class Ui.Setup : Adw.PreferencesDialog {
});
}
private void salt_password (string password, out string token, out string salt) {
const int SALT_BYTES = 8;
uchar salt_bytes[SALT_BYTES];
GCrypt.Random.randomize (salt_bytes);
uchar salt_chars[2*SALT_BYTES+1];
for (int i = 0; i < SALT_BYTES; i += 1) {
salt_chars[2*i+0] = "0123456789abcdef"[(salt_bytes[i]>>4)&0xf];
salt_chars[2*i+1] = "0123456789abcdef"[(salt_bytes[i]>>0)&0xf];
}
salt_chars[2*SALT_BYTES] = 0;
var checksum = new Checksum (ChecksumType.MD5);
checksum.update ((uchar[]) password, -1);
checksum.update (salt_chars, -1);
token = checksum.get_string ();
salt = (string) salt_chars;
}
public void save () {
this.authn_can_edit = false;
Secret.password_store.begin (secret_schema, null, "Subsonic password", this.password, null, (obj, res) => {