- also support sha256
authorMichael Schroeder <mls@suse.de>
Thu, 20 Mar 2008 11:44:04 +0000 (11:44 +0000)
committerMichael Schroeder <mls@suse.de>
Thu, 20 Mar 2008 11:44:04 +0000 (11:44 +0000)
- beautify a bit

src/knownid.h
src/repo_solv.c
src/repodata.c
src/repodata.h
src/repopack.h

index 4817451..b3c5a50 100644 (file)
@@ -74,6 +74,7 @@ KNOWNID(REPOKEY_TYPE_DIRSTRARRAY,     "repokey:type:dirstrarray"),
 KNOWNID(REPOKEY_TYPE_DIRNUMNUMARRAY,   "repokey:type:dirnumnumarray"),
 KNOWNID(REPOKEY_TYPE_MD5,              "repokey:type:md5"),
 KNOWNID(REPOKEY_TYPE_SHA1,             "repokey:type:sha1"),
+KNOWNID(REPOKEY_TYPE_SHA256,           "repokey:type:sha256"),
 
 KNOWNID(SOLVABLE_SUMMARY,              "solvable:summary"),
 KNOWNID(SOLVABLE_DESCRIPTION,          "solvable:description"),
index da3340e..9ede7d3 100644 (file)
@@ -437,6 +437,13 @@ skip_item(Repodata *data, unsigned type, unsigned numid, unsigned numrel)
            read_u8(data);
          break;
        }
+      case REPOKEY_TYPE_SHA256:
+        {
+         int i;
+         for (i = 0; i < SIZEOF_SHA256; i++)
+           read_u8(data);
+         break;
+       }
       case REPOKEY_TYPE_IDARRAY:
       case REPOKEY_TYPE_REL_IDARRAY:
        while ((read_u8(data) & 0xc0) != 0)
@@ -1114,7 +1121,7 @@ repo_add_solv_parent(Repo *repo, FILE *fp, Repodata *parent)
        type = idmap[type];
       else if (parent)
         type = str2id(pool, stringpool_id2str(spool, type), 1);
-      if (type < REPOKEY_TYPE_VOID || type > REPOKEY_TYPE_SHA1)
+      if (type < REPOKEY_TYPE_VOID || type > REPOKEY_TYPE_SHA256)
        {
          pool_debug(pool, SAT_ERROR, "unsupported data type '%s'\n", id2str(pool, type));
          data.error = SOLV_ERROR_UNSUPPORTED;
index 456b055..bb6efa1 100644 (file)
@@ -1082,18 +1082,31 @@ repoadata_add_array(Repodata *data, Id entry, Id keyname, Id keytype, int entrys
     }
 }
 
+static inline int
+checksumtype2len(Id type)
+{
+  switch (type)
+    {
+    case REPOKEY_TYPE_MD5:
+      return SIZEOF_MD5;
+    case REPOKEY_TYPE_SHA1:
+      return SIZEOF_SHA1;
+    case REPOKEY_TYPE_SHA256:
+      return SIZEOF_SHA256;
+    default:
+      return 0;
+    }
+}
+
 void
 repodata_set_bin_checksum(Repodata *data, Id entry, Id keyname, Id type,
                      const unsigned char *str)
 {
   Repokey key;
-  int l;
-  switch (type)
-    {
-      case REPOKEY_TYPE_MD5: l = SIZEOF_MD5; break;
-      case REPOKEY_TYPE_SHA1: l = SIZEOF_SHA1; break;
-      default: return;
-    }
+  int l = checksumtype2len(type);
+
+  if (!l)
+    return;
   key.name = keyname;
   key.type = type;
   key.size = 0;
@@ -1133,17 +1146,14 @@ void
 repodata_set_checksum(Repodata *data, Id entry, Id keyname, Id type,
                      const char *str)
 {
-  int l;
-  switch (type)
-    {
-      case REPOKEY_TYPE_MD5: l = SIZEOF_MD5; break;
-      case REPOKEY_TYPE_SHA1: l = SIZEOF_SHA1; break;
-      default: return;
-    }
-  unsigned char buf[l];
+  unsigned char buf[64];
+  int l = checksumtype2len(type);
+
+  if (!l)
+    return;
   if (hexstr2bytes(buf, str, l) != l)
     {
-      fprintf(stderr, "Invalid hex character in %s\n", str);
+      fprintf(stderr, "Invalid hex character in '%s'\n", str);
       return;
     }
   repodata_set_bin_checksum(data, entry, keyname, type, buf);
@@ -1154,20 +1164,18 @@ repodata_chk2str(Repodata *data, Id type, const char *buf)
 {
   int i, l;
   char *str, *s;
-  switch (type)
-    {
-      case REPOKEY_TYPE_MD5: l = SIZEOF_MD5; break;
-      case REPOKEY_TYPE_SHA1: l = SIZEOF_SHA1; break;
-      default: return id2str(data->repo->pool, ID_EMPTY);
-    }
-  s = str = pool_alloctmpspace(data->repo->pool, 2*l + 1);
-  for (i = 0; i < l; i++, s+=2)
+
+  l = checksumtype2len(type);
+  if (!l)
+    return "";
+  s = str = pool_alloctmpspace(data->repo->pool, 2 * l + 1);
+  for (i = 0; i < l; i++)
     {
       unsigned char v = buf[i];
       unsigned char w = v >> 4;
-      s[0] = w >= 10 ? (w-10)+'a' : w + '0';
+      *s++ = w >= 10 ? w + ('a' - 10) : w + '0';
       w = v & 15;
-      s[1] = w >= 10 ? (w-10)+'a' : w + '0';
+      *s++ = w >= 10 ? w + ('a' - 10) : w + '0';
     }
   *s = 0;
   return str;
index e581035..8c3c338 100644 (file)
@@ -19,8 +19,9 @@
 #include "pool.h"
 #include "dirpool.h"
 
-#define SIZEOF_MD5 16
-#define SIZEOF_SHA1 20
+#define SIZEOF_MD5     16
+#define SIZEOF_SHA1    20
+#define SIZEOF_SHA256  32
 
 struct _Repo;
 struct _Repokey;
index 4ce8991..14e3bd8 100644 (file)
@@ -90,6 +90,9 @@ data_fetch(unsigned char *dp, KeyValue *kv, Repokey *key)
     case REPOKEY_TYPE_SHA1:
       kv->str = (const char *)dp;
       return dp + SIZEOF_SHA1;
+    case REPOKEY_TYPE_SHA256:
+      kv->str = (const char *)dp;
+      return dp + SIZEOF_SHA256;
     case REPOKEY_TYPE_IDARRAY:
       return data_read_ideof(dp, &kv->id, &kv->eof);
     case REPOKEY_TYPE_DIRSTRARRAY:
@@ -127,6 +130,8 @@ data_skip(unsigned char *dp, int type)
       return dp + SIZEOF_MD5;
     case REPOKEY_TYPE_SHA1:
       return dp + SIZEOF_SHA1;
+    case REPOKEY_TYPE_SHA256:
+      return dp + SIZEOF_SHA256;
     case REPOKEY_TYPE_IDARRAY:
     case REPOKEY_TYPE_REL_IDARRAY:
       while ((*dp & 0xc0) != 0)
@@ -190,6 +195,8 @@ data_skip_verify(unsigned char *dp, int type, int maxid, int maxdir)
       return dp + SIZEOF_MD5;
     case REPOKEY_TYPE_SHA1:
       return dp + SIZEOF_SHA1;
+    case REPOKEY_TYPE_SHA256:
+      return dp + SIZEOF_SHA256;
     case REPOKEY_TYPE_ID:
       dp = data_read_id(dp, &id);
       if (id >= maxid)