]>
git.saurik.com Git - apple/libsecurity_codesigning.git/blob - lib/reqmaker.cpp
e4cd62835bbc7cc654140fc40220570eeb0da008
2 * Copyright (c) 2006 Apple Computer, 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 // reqmaker - Requirement assembler
30 namespace CodeSigning
{
34 // Requirement::Makers
36 Requirement::Maker::Maker(Kind k
)
39 mBuffer
= (Requirement
*)malloc(mSize
);
40 mBuffer
->initialize();
42 mPC
= sizeof(Requirement
);
45 // need at least (size) bytes in the creation buffer
46 void Requirement::Maker::require(size_t size
)
48 if (mPC
+ size
> mSize
) {
50 if (mPC
+ size
> mSize
)
52 if (!(mBuffer
= (Requirement
*)realloc(mBuffer
, mSize
)))
53 UnixError::throwMe(ENOMEM
);
57 // allocate (size) bytes at end of buffer and return pointer to that
58 void *Requirement::Maker::alloc(size_t size
)
60 // round size up to preserve alignment
61 size_t usedSize
= LowLevelMemoryUtilities::alignUp(size
, baseAlignment
);
63 void *data
= mBuffer
->at
<void>(mPC
);
66 // clear any padding (avoid random bytes in code image)
67 const uint32_t zero
= 0;
68 memcpy(mBuffer
->at
<void>(mPC
- usedSize
+ size
), &zero
, usedSize
- size
);
74 // put contiguous data blob
75 void Requirement::Maker::putData(const void *data
, size_t length
)
77 put(uint32_t(length
));
78 memcpy(alloc(length
), data
, length
);
81 // Specialized Maker put operations
82 void Requirement::Maker::anchor()
87 void Requirement::Maker::anchor(int slot
, SHA1::Digest digest
)
91 putData(digest
, SHA1::digestLength
);
94 void Requirement::Maker::anchor(int slot
, const void *cert
, size_t length
)
99 hasher
.finish(digest
);
100 anchor(slot
, digest
);
103 void Requirement::Maker::trustedAnchor()
108 void Requirement::Maker::trustedAnchor(int slot
)
114 void Requirement::Maker::infoKey(const string
&key
, const string
&value
)
121 void Requirement::Maker::ident(const string
&identifier
)
127 void Requirement::Maker::cdhash(SHA1::Digest digest
)
130 putData(digest
, SHA1::digestLength
);
134 void *Requirement::Maker::insert(const Label
&label
, size_t length
)
137 memmove(mBuffer
->at
<void>(label
.pos
+ length
),
138 mBuffer
->at
<void>(label
.pos
), mPC
- label
.pos
);
140 return mBuffer
->at
<void>(label
.pos
);
144 Requirement
*Requirement::Maker::make()
146 mBuffer
->length(mPC
);
147 Requirement
*result
= mBuffer
;