From b18c8820a238c5c96e6f30d9baf66c97572f5840 Mon Sep 17 00:00:00 2001 From: psykose Date: Wed, 16 Oct 2024 05:38:01 +0200 Subject: [PATCH] salt_password does nothing with class state so move it out --- src/ui/setup.vala | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/ui/setup.vala b/src/ui/setup.vala index 1db29c2..c57afef 100644 --- a/src/ui/setup.vala +++ b/src/ui/setup.vala @@ -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) => {