X-Git-Url: http://the.earth.li/gitweb/?a=blobdiff_plain;f=keyarray.c;h=85485556929ac0421665a41fc2ceaf6c01f43a5f;hb=23538b7a1fe44e6e04e15d58b6fe809a6ad2ca31;hp=8bade8ca193913330146c3dbe8d1332652692e9d;hpb=46ebdd20784c242ca96b949813d90167349177d9;p=onak.git
diff --git a/keyarray.c b/keyarray.c
index 8bade8c..8548555 100644
--- a/keyarray.c
+++ b/keyarray.c
@@ -13,10 +13,11 @@
* more details.
*
* You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * this program. If not, see .
*/
+#include
+#include
#include
#include
#include
@@ -71,7 +72,7 @@ bool array_add(struct keyarray *array, struct openpgp_fingerprint *fp)
int curpos = 0;
found = false;
- if (array->keys != NULL && array->count > 0) {
+ if (array->size != 0 && array->count > 0) {
bottom = -1;
top = array->count - 1;
while ((top - bottom) > 1) {
@@ -129,3 +130,70 @@ void array_free(struct keyarray *array)
return;
}
+
+static uint8_t hex2bin(char c)
+{
+ if (c >= '0' && c <= '9') {
+ return (c - '0');
+ } else if (c >= 'a' && c <= 'f') {
+ return (c - 'a' + 10);
+ } else if (c >= 'A' && c <= 'F') {
+ return (c - 'A' + 10);
+ }
+
+ return 255;
+}
+
+bool array_load(struct keyarray *array, const char *file)
+{
+ struct openpgp_fingerprint fp;
+ char curline[1024];
+ FILE *fpfile;
+ int i;
+
+ fpfile = fopen(file, "r");
+
+ if (fpfile != NULL) {
+ if (!fgets(curline, sizeof(curline) - 1, fpfile)) {
+ fclose(fpfile);
+ return false;
+ }
+
+ while (!feof(fpfile)) {
+ /* Strip any trailing white space */
+ for (i = strlen(curline) - 1;
+ i >= 0 && isspace(curline[i]); i--) {
+ curline[i] = 0;
+ }
+ i++;
+ //if ((i % 2) != 0) {
+ // break;
+ //}
+ i >>= 1;
+ if (curline[0] == '#') {
+ // Comment line, ignore
+ } else if (i == FINGERPRINT_V3_LEN ||
+ i == FINGERPRINT_V4_LEN ||
+ i == FINGERPRINT_V5_LEN) {
+ fp.length = i;
+ for (i = 0; i < fp.length; i++) {
+ fp.fp[i] = hex2bin(curline[i * 2]);
+ fp.fp[i] <<= 4;
+ fp.fp[i] |=
+ hex2bin(curline[i * 2 + 1]);
+ }
+ array_add(array, &fp);
+ } else {
+ printf("Bad line.\n");
+ }
+
+ if (!fgets(curline, sizeof(curline) - 1, fpfile)) {
+ break;
+ }
+ }
+
+ fclose(fpfile);
+ }
+
+ return (array->count != 0);
+}