]> git.saurik.com Git - apple/libsecurity_codesigning.git/blame - lib/cdbuilder.h
libsecurity_codesigning-55037.15.tar.gz
[apple/libsecurity_codesigning.git] / lib / cdbuilder.h
CommitLineData
7d31e928 1/*
f60086fc 2 * Copyright (c) 2006-2010 Apple Inc. All Rights Reserved.
7d31e928
A
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// cdbuilder - constructor for CodeDirectories
26//
27#ifndef _H_CDBUILDER
28#define _H_CDBUILDER
29
30#include "codedirectory.h"
31
32
33namespace Security {
34namespace CodeSigning {
35
36
37//
38// Builder can construct CodeDirectories from pieces:
f60086fc 39// Builder builder(...);
7d31e928
A
40// builder.variousSetters(withSuitableData);
41// CodeDirectory *result = builder.build();
42// Builder is not reusable.
43//
44class CodeDirectory::Builder {
45public:
f60086fc 46 Builder(HashAlgorithm digestAlgorithm);
d1c1ab47 47 ~Builder();
7d31e928
A
48
49 void executable(string path, size_t pagesize, size_t offset, size_t length);
50 void reopen(string path, size_t offset, size_t length);
51
f60086fc 52 void specialSlot(SpecialSlot slot, CFDataRef data);
7d31e928
A
53 void identifier(const std::string &code) { mIdentifier = code; }
54 void flags(uint32_t f) { mFlags = f; }
55
d1c1ab47
A
56 Scatter *scatter(unsigned count); // allocate that many scatter elements (w/o sentinel)
57 Scatter *scatter() { return mScatter; } // return already allocated scatter vector
58
7d31e928
A
59 size_t size(); // calculate size
60 CodeDirectory *build(); // build CodeDirectory and return it
f60086fc
A
61
62private:
63 DynamicHash *getHash() const { return CodeDirectory::hashFor(this->mHashType); }
64
65 Hashing::Byte *specialSlot(SpecialSlot slot)
66 { assert(slot > 0 && slot <= cdSlotMax); return mSpecial + (slot - 1) * mDigestLength; }
67 Hashing::Byte *specialSlot(SpecialSlot slot) const
68 { assert(slot > 0 && slot <= cdSlotMax); return mSpecial + (slot - 1) * mDigestLength; }
7d31e928
A
69
70private:
f60086fc 71 Hashing::Byte *mSpecial; // array of special slot hashes
7d31e928
A
72 UnixPlusPlus::AutoFileDesc mExec; // main executable file
73 size_t mExecOffset; // starting offset in mExec
74 size_t mExecLength; // total bytes of file to sign
75 size_t mPageSize; // page size of executable (bytes)
76 uint32_t mFlags; // CodeDirectory flags
f60086fc
A
77 uint32_t mHashType; // digest algorithm code
78 uint32_t mDigestLength; // number of bytes in a single glue digest
7d31e928
A
79 std::string mIdentifier; // canonical identifier
80
81 size_t mSpecialSlots; // highest special slot set
82 size_t mCodeSlots; // number of code pages (slots)
83
d1c1ab47
A
84 Scatter *mScatter; // scatter vector
85 size_t mScatterSize; // number of scatter elements allocated (incl. sentinel)
86
7d31e928
A
87 CodeDirectory *mDir; // what we're building
88};
89
90
91} // CodeSigning
92} // Security
93
94
95#endif //_H_CDBUILDER