#ifndef _H_RSIGN
#define _H_RSIGN
#include "renum.h"
#include "codedirectory.h"
#include <security_utilities/utilities.h>
#include <security_utilities/cfutilities.h>
#include <security_utilities/hashing.h>
#include "regex.h"
#include <CoreFoundation/CoreFoundation.h>
#include <vector>
namespace Security {
namespace CodeSigning {
class ResourceBuilder : public ResourceEnumerator {
public:
ResourceBuilder(const std::string &root, CFDictionaryRef rules, CodeDirectory::HashAlgorithm hashType);
~ResourceBuilder();
CFDictionaryRef build();
enum Action {
optional = 0x01, omitted = 0x02, exclusion = 0x04, };
typedef unsigned int Weight;
public:
class Rule : private regex_t {
public:
Rule(const std::string &pattern, Weight weight, uint32_t flags);
~Rule();
bool match(const char *s) const;
const Weight weight;
const uint32_t flags;
};
void addRule(Rule *rule) { mRules.push_back(rule); }
void addExclusion(const std::string &pattern) { mRules.insert(mRules.begin(), new Rule(pattern, 0, exclusion)); }
static std::string escapeRE(const std::string &s);
FTSENT *next(std::string &path, Rule * &rule);
protected:
void addRule(CFTypeRef key, CFTypeRef value);
CFDataRef hashFile(const char *path);
DynamicHash *getHash() const { return CodeDirectory::hashFor(this->mHashType); }
private:
CFCopyRef<CFDictionaryRef> mRawRules;
typedef std::vector<Rule *> Rules;
Rules mRules;
CodeDirectory::HashAlgorithm mHashType;
};
class ResourceSeal {
public:
ResourceSeal(CFTypeRef ref);
public:
operator bool () const { return mHash; }
bool operator ! () const { return mHash == NULL; }
const SHA1::Byte *hash() const { return CFDataGetBytePtr(mHash); }
bool optional() const { return mOptional; }
private:
CFDataRef mHash;
int mOptional;
};
} }
#endif // !_H_RSIGN