/ OSX / libsecurity_codesigning / lib / filediskrep.h
filediskrep.h
 1  /*
 2   * Copyright (c) 2006-2007,2011 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  // filediskrep - single-file executable disk representation
26  //
27  #ifndef _H_FILEDISKREP
28  #define _H_FILEDISKREP
29  
30  #include "singlediskrep.h"
31  #include "machorep.h"
32  #include <security_utilities/cfutilities.h>
33  
34  namespace Security {
35  namespace CodeSigning {
36  
37  
38  //
39  // A FileDiskRep represents a single code file on disk. We assume nothing about
40  // the format or contents of the file and impose no structure on it, other than
41  // assuming that all relevant code is contained in the file's data bytes.
42  // By default, we seal the entire file data as a single page.
43  //
44  // This is the ultimate fallback disk format. It is used if no other pattern
45  // applies. As such it is important that we do not introduce any assumptions
46  // here. Know that you do not know what any of the file means.
47  //
48  // FileDiskrep stores components in extended file attributes, one attribute
49  // per component. Note that this imposes size limitations on component size
50  // that may well be prohibitive in some applications.
51  //
52  // This DiskRep does not support resource sealing.
53  //
54  class FileDiskRep : public SingleDiskRep {
55  public:
56  	FileDiskRep(const char *path);
57  	
58  	CFDataRef component(CodeDirectory::SpecialSlot slot);
59  	std::string format();
60  	
61  	const Requirements *defaultRequirements(const Architecture *arch, const SigningContext &ctx);
62  	
63  public:
64  	DiskRep::Writer *writer();
65  	class Writer;
66  	friend class Writer;
67  	
68  protected:
69  	CFDataRef getAttribute(const char *name);
70  	static std::string attrName(const char *name);
71  };
72  
73  
74  //
75  // The write side of a FileDiskRep
76  //
77  class FileDiskRep::Writer : public SingleDiskRep::Writer {
78  	friend class FileDiskRep;
79  public:
80  	void component(CodeDirectory::SpecialSlot slot, CFDataRef data);
81      void flush();
82  	void remove();
83  	bool preferredStore();
84  
85  protected:
86  	Writer(FileDiskRep *r) : SingleDiskRep::Writer(r, writerLastResort) { }
87  	RefPointer<FileDiskRep> rep;
88      std::set<std::string> mWrittenAttributes;
89  };
90  
91  
92  } // end namespace CodeSigning
93  } // end namespace Security
94  
95  #endif // !_H_FILEDISKREP