+CFDataRef CodeSigningHost::Guest::attrData() const
+{
+ if (!mAttrData)
+ mAttrData = makeCFData(this->attributes.get());
+ return mAttrData;
+}
+
+
+void CodeSigningHost::Guest::setHash(const CssmData &given, bool generate)
+{
+ if (given.length()) // explicitly given
+ this->cdhash.take(makeCFData(given));
+ else if (CFTypeRef hash = CFDictionaryGetValue(this->attributes, kSecGuestAttributeHash))
+ if (CFGetTypeID(hash) == CFDataGetTypeID())
+ this->cdhash = CFDataRef(hash);
+ else
+ MacOSError::throwMe(errSecCSHostProtocolInvalidHash);
+ else if (generate) { // generate from path (well, try)
+ CFRef<SecStaticCodeRef> code;
+ MacOSError::check(SecStaticCodeCreateWithPath(CFTempURL(this->path), kSecCSDefaultFlags, &code.aref()));
+ CFRef<CFDictionaryRef> info;
+ MacOSError::check(SecCodeCopySigningInformation(code, kSecCSDefaultFlags, &info.aref()));
+ this->cdhash = CFDataRef(CFDictionaryGetValue(info, kSecCodeInfoUnique));
+ }
+}
+