]> git.saurik.com Git - apple/libsecurity_codesigning.git/blob - lib/singlediskrep.cpp
libsecurity_codesigning-32953.tar.gz
[apple/libsecurity_codesigning.git] / lib / singlediskrep.cpp
1 /*
2 * Copyright (c) 2006-2007 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 //
25 // singlediskrep - semi-abstract diskrep for a single file of some kind
26 //
27 #include "singlediskrep.h"
28
29
30 namespace Security {
31 namespace CodeSigning {
32
33 using namespace UnixPlusPlus;
34
35
36 //
37 // Construct a SingleDiskRep
38 //
39 SingleDiskRep::SingleDiskRep(const char *path)
40 : mPath(path)
41 {
42 }
43
44
45 //
46 // Both the canonical and main executable path of a SingleDiskRep is, well, its path.
47 //
48 CFURLRef SingleDiskRep::canonicalPath()
49 {
50 return makeCFURL(mPath);
51 }
52
53 string SingleDiskRep::mainExecutablePath()
54 {
55 return mPath;
56 }
57
58
59 //
60 // The recommended identifier of a SingleDiskRep is, absent any better clue,
61 // the basename of its path.
62 //
63 string SingleDiskRep::recommendedIdentifier()
64 {
65 string::size_type p = mPath.rfind('/');
66 if (p == string::npos)
67 return mPath;
68 else
69 return mPath.substr(p+1);
70 }
71
72
73 //
74 // The default signing limit is the size of the file.
75 // This will do unless the signing data gets creatively stuck in there somewhere.
76 //
77 size_t SingleDiskRep::signingLimit()
78 {
79 return fd().fileSize();
80 }
81
82
83 //
84 // A lazily opened read-only file descriptor for the path.
85 //
86 FileDesc &SingleDiskRep::fd()
87 {
88 if (!mFd)
89 mFd.open(mPath, O_RDONLY);
90 return mFd;
91 }
92
93
94 //
95 // Flush cached state
96 //
97 void SingleDiskRep::flush()
98 {
99 mFd.close();
100 }
101
102
103 //
104 // Prototype Writers
105 //
106 FileDesc &SingleDiskRep::Writer::fd()
107 {
108 if (!mFd)
109 mFd.open(rep->path(), O_RDWR);
110 return mFd;
111 }
112
113
114 } // end namespace CodeSigning
115 } // end namespace Security