]>
git.saurik.com Git - apple/libsecurity_codesigning.git/blob - lib/singlediskrep.cpp
ab3064d01a5b9f88b15db3de9084d187f161bedb
2 * Copyright (c) 2006-2007 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 // singlediskrep - semi-abstract diskrep for a single file of some kind
27 #include "singlediskrep.h"
28 #include "csutilities.h"
29 #include <security_utilities/cfutilities.h>
32 namespace CodeSigning
{
34 using namespace UnixPlusPlus
;
38 // Construct a SingleDiskRep
40 SingleDiskRep::SingleDiskRep(const std::string
&path
)
47 // The default binary identification of a SingleDiskRep is the (SHA-1) hash
48 // of the entire file itself.
50 CFDataRef
SingleDiskRep::identification()
54 hashFileData(this->fd(), hash
);
57 return makeCFData(digest
, sizeof(digest
));
62 // Both the canonical and main executable path of a SingleDiskRep is, well, its path.
64 CFURLRef
SingleDiskRep::canonicalPath()
66 return makeCFURL(mPath
);
69 string
SingleDiskRep::mainExecutablePath()
76 // The recommended identifier of a SingleDiskRep is, absent any better clue,
77 // the basename of its path.
79 string
SingleDiskRep::recommendedIdentifier()
81 string::size_type p
= mPath
.rfind('/');
82 if (p
== string::npos
)
85 return mPath
.substr(p
+1);
90 // The default signing limit is the size of the file.
91 // This will do unless the signing data gets creatively stuck in there somewhere.
93 size_t SingleDiskRep::signingLimit()
95 return fd().fileSize();
100 // A lazily opened read-only file descriptor for the path.
102 FileDesc
&SingleDiskRep::fd()
105 mFd
.open(mPath
, O_RDONLY
);
111 // Flush cached state
113 void SingleDiskRep::flush()
122 FileDesc
&SingleDiskRep::Writer::fd()
125 mFd
.open(rep
->path(), O_RDWR
);
130 } // end namespace CodeSigning
131 } // end namespace Security