Mercurial > ~mikael > mcabber > hg
comparison mcabber/mcabber/utils.c @ 2197:189abf03ef24
Fix fingerprint management
(Reported by Sven Gaerner in issue #134)
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sun, 11 Oct 2015 17:17:35 +0200 |
parents | 87244845fd9c |
children | 1591518a33b9 |
comparison
equal
deleted
inserted
replaced
2196:8811fe9d6ef0 | 2197:189abf03ef24 |
---|---|
153 return g_strdup_printf("%s%s", homedir, fname+1); | 153 return g_strdup_printf("%s%s", homedir, fname+1); |
154 } | 154 } |
155 return g_strdup(fname); | 155 return g_strdup(fname); |
156 } | 156 } |
157 | 157 |
158 void fingerprint_to_hex(const unsigned char *fpr, char hex[49]) | 158 void fingerprint_to_hex(const unsigned char *fpr, char hex[48]) |
159 { | 159 { |
160 int i; | 160 int i; |
161 char *p; | 161 char *p; |
162 | 162 |
163 hex[0] = 0; | |
164 if (!fpr) return; | |
165 | |
163 for (p = hex, i = 0; i < 15; i++, p+=3) | 166 for (p = hex, i = 0; i < 15; i++, p+=3) |
164 g_sprintf(p, "%02X:", fpr[i]); | 167 g_snprintf(p, 4, "%02X:", fpr[i]); |
165 g_sprintf(p, "%02X", fpr[i]); | 168 g_snprintf(p, 3, "%02X", fpr[i]); |
166 hex[48] = '\0'; | 169 } |
167 } | 170 |
168 | 171 gboolean hex_to_fingerprint(const char *hex, char fpr[17]) |
169 gboolean hex_to_fingerprint(const char *hex, char fpr[16]) | |
170 { | 172 { |
171 int i; | 173 int i; |
172 char *p; | 174 const char *p; |
173 | 175 |
176 fpr[0] = 0; | |
174 if (strlen(hex) != 47) | 177 if (strlen(hex) != 47) |
175 return FALSE; | 178 return FALSE; |
176 for (i = 0, p = (char*)hex; *p && *(p+1); i++, p += 3) | 179 for (i = 0, p = hex; *p && *(p+1); i++, p += 3) { |
177 fpr[i] = (char) g_ascii_strtoull (p, NULL, 16); | 180 if (*(p+2) && (*(p+2) != ':')) { |
181 fpr[i] = 0; | |
182 return FALSE; | |
183 } | |
184 fpr[i] = (char)g_ascii_strtoull(p, NULL, 16); | |
185 } | |
186 fpr[i] = 0; | |
178 return TRUE; | 187 return TRUE; |
179 } | 188 } |
180 | 189 |
181 static gboolean tracelog_create(void) | 190 static gboolean tracelog_create(void) |
182 { | 191 { |