summaryrefslogtreecommitdiff
path: root/contrib/keychain-mcd/crypto_osx.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/keychain-mcd/crypto_osx.c')
-rw-r--r--contrib/keychain-mcd/crypto_osx.c57
1 files changed, 31 insertions, 26 deletions
diff --git a/contrib/keychain-mcd/crypto_osx.c b/contrib/keychain-mcd/crypto_osx.c
index 87ba09b..092e64f 100644
--- a/contrib/keychain-mcd/crypto_osx.c
+++ b/contrib/keychain-mcd/crypto_osx.c
@@ -31,45 +31,50 @@
#include "crypto_osx.h"
#include <err.h>
-void printErrorMsg(const char *func, CFErrorRef error)
+void
+printErrorMsg(const char *func, CFErrorRef error)
{
- CFStringRef desc = CFErrorCopyDescription(error);
- warnx("%s failed: %s", func, CFStringGetCStringPtr(desc, kCFStringEncodingUTF8));
- CFRelease(desc);
+ CFStringRef desc = CFErrorCopyDescription(error);
+ warnx("%s failed: %s", func, CFStringGetCStringPtr(desc, kCFStringEncodingUTF8));
+ CFRelease(desc);
}
-void printErrorStatusMsg(const char *func, OSStatus status)
+void
+printErrorStatusMsg(const char *func, OSStatus status)
{
- CFStringRef error;
- error = SecCopyErrorMessageString(status, NULL);
- if (error)
+ CFStringRef error;
+ error = SecCopyErrorMessageString(status, NULL);
+ if (error)
{
- warnx("%s failed: %s", func, CFStringGetCStringPtr(error, kCFStringEncodingUTF8));
- CFRelease(error);
+ warnx("%s failed: %s", func, CFStringGetCStringPtr(error, kCFStringEncodingUTF8));
+ CFRelease(error);
+ }
+ else
+ {
+ warnx("%s failed: %X", func, (int)status);
}
- else
- warnx("%s failed: %X", func, (int)status);
}
-void signData(SecIdentityRef identity, const uint8_t *from, int flen, uint8_t *to, size_t *tlen)
+void
+signData(SecIdentityRef identity, const uint8_t *from, int flen, uint8_t *to, size_t *tlen)
{
- SecKeyRef privateKey = NULL;
- OSStatus status;
+ SecKeyRef privateKey = NULL;
+ OSStatus status;
- status = SecIdentityCopyPrivateKey(identity, &privateKey);
- if (status != noErr)
+ status = SecIdentityCopyPrivateKey(identity, &privateKey);
+ if (status != noErr)
{
- printErrorStatusMsg("signData: SecIdentityCopyPrivateKey", status);
- *tlen = 0;
- return;
+ printErrorStatusMsg("signData: SecIdentityCopyPrivateKey", status);
+ *tlen = 0;
+ return;
}
- status = SecKeyRawSign(privateKey, kSecPaddingPKCS1, from, flen, to, tlen);
- CFRelease(privateKey);
- if (status != noErr)
+ status = SecKeyRawSign(privateKey, kSecPaddingPKCS1, from, flen, to, tlen);
+ CFRelease(privateKey);
+ if (status != noErr)
{
- printErrorStatusMsg("signData: SecKeyRawSign", status);
- *tlen = 0;
- return;
+ printErrorStatusMsg("signData: SecKeyRawSign", status);
+ *tlen = 0;
+ return;
}
}