]> git.saurik.com Git - apple/libsecurity_codesigning.git/blobdiff - lib/singlediskrep.cpp
libsecurity_codesigning-55037.15.tar.gz
[apple/libsecurity_codesigning.git] / lib / singlediskrep.cpp
index 8331a5a5eb5ea0d1716dde90bd015c381d93b55c..154ed2e927e9bc5f278e3efd6b27e2cb9b9c571a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006-2007 Apple Inc. All Rights Reserved.
+ * Copyright (c) 2006-2010 Apple Inc. All Rights Reserved.
  * 
  * @APPLE_LICENSE_HEADER_START@
  * 
@@ -25,7 +25,8 @@
 // singlediskrep - semi-abstract diskrep for a single file of some kind
 //
 #include "singlediskrep.h"
-
+#include "csutilities.h"
+#include <security_utilities/cfutilities.h>
 
 namespace Security {
 namespace CodeSigning {
@@ -36,12 +37,27 @@ using namespace UnixPlusPlus;
 //
 // Construct a SingleDiskRep
 //
-SingleDiskRep::SingleDiskRep(const char *path)
+SingleDiskRep::SingleDiskRep(const std::string &path)
        : mPath(path)
 {
 }
 
 
+//
+// The default binary identification of a SingleDiskRep is the (SHA-1) hash
+// of the entire file itself.
+//
+CFDataRef SingleDiskRep::identification()
+{
+       SHA1 hash;
+       this->fd().seek(0);
+       hashFileData(this->fd(), &hash);
+       SHA1::Digest digest;
+       hash.finish(digest);
+       return makeCFData(digest, sizeof(digest));
+}
+
+
 //
 // Both the canonical and main executable path of a SingleDiskRep is, well, its path.
 //
@@ -56,20 +72,6 @@ string SingleDiskRep::mainExecutablePath()
 }
 
 
-//
-// The recommended identifier of a SingleDiskRep is, absent any better clue,
-// the basename of its path.
-//
-string SingleDiskRep::recommendedIdentifier()
-{      
-       string::size_type p = mPath.rfind('/');
-       if (p == string::npos)
-               return mPath;
-       else
-               return mPath.substr(p+1);
-}
-
-
 //
 // The default signing limit is the size of the file.
 // This will do unless the signing data gets creatively stuck in there somewhere.
@@ -100,6 +102,16 @@ void SingleDiskRep::flush()
 }
 
 
+//
+// The recommended identifier of a SingleDiskRep is, absent any better clue,
+// the basename of its path.
+//
+string SingleDiskRep::recommendedIdentifier(const SigningContext &)
+{
+       return canonicalIdentifier(mPath);
+}
+
+
 //
 // Prototype Writers
 //