Prechádzať zdrojové kódy

Core Foundation and Security vendor libraries.

Vitalii Kravchenko 1 rok pred
rodič
commit
befb0f7868

+ 1 - 1
core/crypto/rand_bsd.odin

@@ -11,6 +11,6 @@ _rand_bytes :: proc(dst: []byte) {
 	arc4random_buf(raw_data(dst), len(dst))
 }
 
-_has_rand_bytes :: proc () -> bool {
+_has_rand_bytes :: proc() -> bool {
 	return true
 }

+ 8 - 6
core/crypto/rand_darwin.odin

@@ -1,16 +1,18 @@
 package crypto
 
 import "core:fmt"
-import "core:sys/darwin"
+
+import CF "core:sys/darwin/CoreFoundation"
+import Sec "core:sys/darwin/Security"
 
 _rand_bytes :: proc(dst: []byte) {
-	res := darwin.SecRandomCopyBytes(count=len(dst), bytes=raw_data(dst))
-	if res != .Success {
-		msg := darwin.CFStringCopyToOdinString(darwin.SecCopyErrorMessageString(res))
-		panic(fmt.tprintf("crypto/rand_bytes: SecRandomCopyBytes returned non-zero result: %v %s", res, msg))
+	err := Sec.RandomCopyBytes(count=len(dst), bytes=raw_data(dst))
+	if err != .Success {
+        msg := CF.StringCopyToOdinString(Sec.CopyErrorMessageString(err))
+        panic(fmt.tprintf("crypto/rand_bytes: SecRandomCopyBytes returned non-zero result: %v %s", err, msg))
 	}
 }
 
-_has_rand_bytes :: proc () -> bool {
+_has_rand_bytes :: proc() -> bool {
 	return true
 }

+ 1 - 1
core/crypto/rand_generic.odin

@@ -10,6 +10,6 @@ _rand_bytes :: proc(dst: []byte) {
 	unimplemented("crypto: rand_bytes not supported on this OS")
 }
 
-_has_rand_bytes :: proc () -> bool {
+_has_rand_bytes :: proc() -> bool {
 	return false
 }

+ 1 - 1
core/crypto/rand_js.odin

@@ -19,6 +19,6 @@ _rand_bytes :: proc(dst: []byte) {
 	}
 }
 
-_has_rand_bytes :: proc () -> bool {
+_has_rand_bytes :: proc() -> bool {
 	return true
 }

+ 1 - 1
core/crypto/rand_linux.odin

@@ -35,6 +35,6 @@ _rand_bytes :: proc (dst: []byte) {
 	}
 }
 
-_has_rand_bytes :: proc () -> bool {
+_has_rand_bytes :: proc() -> bool {
 	return true
 }

+ 1 - 1
core/crypto/rand_windows.odin

@@ -22,6 +22,6 @@ _rand_bytes :: proc(dst: []byte) {
 	}
 }
 
-_has_rand_bytes :: proc () -> bool {
+_has_rand_bytes :: proc() -> bool {
 	return true
 }

+ 2 - 2
core/os/stat.odin

@@ -3,8 +3,8 @@ package os
 import "core:time"
 
 File_Info :: struct {
-	fullpath: string,
-	name:     string,
+	fullpath: string, // allocated
+	name:     string, // uses `fullpath` as underlying data
 	size:     i64,
 	mode:     File_Mode,
 	is_dir:   bool,

+ 34 - 0
core/sys/darwin/CoreFoundation/CFBase.odin

@@ -0,0 +1,34 @@
+package CoreFoundation
+
+foreign import CoreFoundation "system:CoreFoundation.framework"
+
+TypeID      :: distinct uint
+OptionFlags :: distinct uint
+HashCode    :: distinct uint
+Index       :: distinct int
+TypeRef     :: distinct rawptr
+
+Range :: struct {
+	location: Index,
+	length:   Index,
+}
+
+foreign CoreFoundation {
+	// Releases a Core Foundation object.
+	CFRelease :: proc(cf: TypeRef) ---
+}
+
+// Releases a Core Foundation object.
+Release :: proc {
+	ReleaseObject,
+	ReleaseString,
+}
+
+ReleaseObject :: #force_inline proc(cf: TypeRef) {
+	CFRelease(cf)
+}
+
+// Releases a Core Foundation string.
+ReleaseString :: #force_inline proc(theString: String) {
+	CFRelease(TypeRef(theString))
+}

+ 203 - 0
core/sys/darwin/CoreFoundation/CFString.odin

@@ -0,0 +1,203 @@
+package CoreFoundation
+
+import "base:runtime"
+
+foreign import CoreFoundation "system:CoreFoundation.framework"
+
+String :: distinct TypeRef // same as CFStringRef
+
+StringEncoding :: distinct u32
+
+StringBuiltInEncodings :: enum StringEncoding {
+	MacRoman = 0,
+	WindowsLatin1 = 0x0500,
+	ISOLatin1 = 0x0201,
+	NextStepLatin = 0x0B01,
+	ASCII = 0x0600,
+	Unicode = 0x0100,
+	UTF8 = 0x08000100,
+	NonLossyASCII = 0x0BFF,
+
+	UTF16 = 0x0100,
+	UTF16BE = 0x10000100,
+	UTF16LE = 0x14000100,
+
+	UTF32 = 0x0c000100,
+	UTF32BE = 0x18000100,
+	UTF32LE = 0x1c000100,
+}
+
+StringEncodings :: enum Index {
+    MacJapanese = 1,
+    MacChineseTrad = 2,
+    MacKorean = 3,
+    MacArabic = 4,
+    MacHebrew = 5,
+    MacGreek = 6,
+    MacCyrillic = 7,
+    MacDevanagari = 9,
+    MacGurmukhi = 10,
+    MacGujarati = 11,
+    MacOriya = 12,
+    MacBengali = 13,
+    MacTamil = 14,
+    MacTelugu = 15,
+    MacKannada = 16,
+    MacMalayalam = 17,
+    MacSinhalese = 18,
+    MacBurmese = 19,
+    MacKhmer = 20,
+    MacThai = 21,
+    MacLaotian = 22,
+    MacGeorgian = 23,
+    MacArmenian = 24,
+    MacChineseSimp = 25,
+    MacTibetan = 26,
+    MacMongolian = 27,
+    MacEthiopic = 28,
+    MacCentralEurRoman = 29,
+    MacVietnamese = 30,
+    MacExtArabic = 31,
+    MacSymbol = 33,
+    MacDingbats = 34,
+    MacTurkish = 35,
+    MacCroatian = 36,
+    MacIcelandic = 37,
+    MacRomanian = 38,
+    MacCeltic = 39,
+    MacGaelic = 40,
+    MacFarsi = 0x8C,
+    MacUkrainian = 0x98,
+    MacInuit = 0xEC,
+    MacVT100 = 0xFC,
+    MacHFS = 0xFF,
+    ISOLatin2 = 0x0202,
+    ISOLatin3 = 0x0203,
+    ISOLatin4 = 0x0204,
+    ISOLatinCyrillic = 0x0205,
+    ISOLatinArabic = 0x0206,
+    ISOLatinGreek = 0x0207,
+    ISOLatinHebrew = 0x0208,
+    ISOLatin5 = 0x0209,
+    ISOLatin6 = 0x020A,
+    ISOLatinThai = 0x020B,
+    ISOLatin7 = 0x020D,
+    ISOLatin8 = 0x020E,
+    ISOLatin9 = 0x020F,
+    ISOLatin10 = 0x0210,
+    DOSLatinUS = 0x0400,
+    DOSGreek = 0x0405,
+    DOSBalticRim = 0x0406,
+    DOSLatin1 = 0x0410,
+    DOSGreek1 = 0x0411,
+    DOSLatin2 = 0x0412,
+    DOSCyrillic = 0x0413,
+    DOSTurkish = 0x0414,
+    DOSPortuguese = 0x0415,
+    DOSIcelandic = 0x0416,
+    DOSHebrew = 0x0417,
+    DOSCanadianFrench = 0x0418,
+    DOSArabic = 0x0419,
+    DOSNordic = 0x041A,
+    DOSRussian = 0x041B,
+    DOSGreek2 = 0x041C,
+    DOSThai = 0x041D,
+    DOSJapanese = 0x0420,
+    DOSChineseSimplif = 0x0421,
+    DOSKorean = 0x0422,
+    DOSChineseTrad = 0x0423,
+    WindowsLatin2 = 0x0501,
+    WindowsCyrillic = 0x0502,
+    WindowsGreek = 0x0503,
+    WindowsLatin5 = 0x0504,
+    WindowsHebrew = 0x0505,
+    WindowsArabic = 0x0506,
+    WindowsBalticRim = 0x0507,
+    WindowsVietnamese = 0x0508,
+    WindowsKoreanJohab = 0x0510,
+    ANSEL = 0x0601,
+    JIS_X0201_76 = 0x0620,
+    JIS_X0208_83 = 0x0621,
+    JIS_X0208_90 = 0x0622,
+    JIS_X0212_90 = 0x0623,
+    JIS_C6226_78 = 0x0624,
+    ShiftJIS_X0213 = 0x0628,
+    ShiftJIS_X0213_MenKuTen = 0x0629,
+    GB_2312_80 = 0x0630,
+    GBK_95 = 0x0631,
+    GB_18030_2000 = 0x0632,
+    KSC_5601_87 = 0x0640,
+    KSC_5601_92_Johab = 0x0641,
+    CNS_11643_92_P1 = 0x0651,
+    CNS_11643_92_P2 = 0x0652,
+    CNS_11643_92_P3 = 0x0653,
+    ISO_2022_JP = 0x0820,
+    ISO_2022_JP_2 = 0x0821,
+    ISO_2022_JP_1 = 0x0822,
+    ISO_2022_JP_3 = 0x0823,
+    ISO_2022_CN = 0x0830,
+    ISO_2022_CN_EXT = 0x0831,
+    ISO_2022_KR = 0x0840,
+    EUC_JP = 0x0920,
+    EUC_CN = 0x0930,
+    EUC_TW = 0x0931,
+    EUC_KR = 0x0940,
+    ShiftJIS = 0x0A01,
+    KOI8_R = 0x0A02,
+    Big5 = 0x0A03,
+    MacRomanLatin1 = 0x0A04,
+    HZ_GB_2312 = 0x0A05,
+    Big5_HKSCS_1999 = 0x0A06,
+    VISCII = 0x0A07,
+    KOI8_U = 0x0A08,
+    Big5_E = 0x0A09,
+    NextStepJapanese = 0x0B02,
+    EBCDIC_US = 0x0C01,
+    EBCDIC_CP037 = 0x0C02,
+    UTF7 = 0x04000100,
+    UTF7_IMAP = 0x0A10,
+    ShiftJIS_X0213_00 = 0x0628, // Deprecated. Use `ShiftJIS_X0213` instead.
+}
+
+@(link_prefix = "CF", default_calling_convention = "c")
+foreign CoreFoundation {
+	// Copies the character contents of a string to a local C string buffer after converting the characters to a given encoding.
+	StringGetCString :: proc(theString: String, buffer: [^]byte, bufferSize: Index, encoding: StringEncoding) -> b8 ---
+
+	// Returns the number (in terms of UTF-16 code pairs) of Unicode characters in a string.
+	StringGetLength :: proc(theString: String) -> Index ---
+
+	// Returns the maximum number of bytes a string of a specified length (in Unicode characters) will take up if encoded in a specified encoding.
+	StringGetMaximumSizeForEncoding :: proc(length: Index, encoding: StringEncoding) -> Index ---
+
+	// Fetches a range of the characters from a string into a byte buffer after converting the characters to a specified encoding.
+	StringGetBytes :: proc(thestring: String, range: Range, encoding: StringEncoding, lossByte: u8, isExternalRepresentation: b8, buffer: [^]byte, maxBufLen: Index, usedBufLen: ^Index) -> Index ---
+
+	StringIsEncodingAvailable :: proc(encoding: StringEncoding) -> bool ---
+
+	@(link_name = "__CFStringMakeConstantString")
+	StringMakeConstantString :: proc "c" (#const c: cstring) -> String ---
+}
+
+STR :: StringMakeConstantString
+
+StringCopyToOdinString :: proc(
+	theString: String,
+	allocator := context.allocator,
+) -> (
+	str: string,
+	ok: bool,
+) #optional_ok {
+	length := StringGetLength(theString)
+	max := StringGetMaximumSizeForEncoding(length, StringEncoding(StringBuiltInEncodings.UTF8))
+
+	buf, err := make([]byte, max, allocator)
+	if err != nil do return
+
+	raw_str := runtime.Raw_String {
+		data = raw_data(buf),
+	}
+	StringGetBytes(theString, {0, length}, StringEncoding(StringBuiltInEncodings.UTF8), 0, false, raw_data(buf), max, (^Index)(&raw_str.len))
+
+	return transmute(string)raw_str, true
+}

+ 6 - 9
core/sys/darwin/Foundation/NSString.odin

@@ -23,12 +23,9 @@ StringEncoding :: enum UInteger {
 	WindowsCP1250     = 15,
 	ISO2022JP         = 21,
 	MacOSRoman        = 30,
-
 	UTF16             = Unicode,
-
 	UTF16BigEndian    = 0x90000100,
 	UTF16LittleEndian = 0x94000100,
-
 	UTF32             = 0x8c000100,
 	UTF32BigEndian    = 0x98000100,
 	UTF32LittleEndian = 0x9c000100,
@@ -49,12 +46,9 @@ StringCompareOption :: enum UInteger {
 
 unichar :: distinct u16
 
-@(link_prefix="NS", default_calling_convention="c")
-foreign Foundation {
-	StringFromClass :: proc(cls: Class) -> ^String ---
-}
-
 AT :: MakeConstantString
+
+// CFString is 'toll-free bridged' with its Cocoa Foundation counterpart, NSString.
 MakeConstantString :: proc "c" (#const c: cstring) -> ^String {
 	foreign Foundation {
 		__CFStringMakeConstantString :: proc "c" (c: cstring) -> ^String ---
@@ -62,6 +56,10 @@ MakeConstantString :: proc "c" (#const c: cstring) -> ^String {
 	return __CFStringMakeConstantString(c)
 }
 
+@(link_prefix="NS", default_calling_convention="c")
+foreign Foundation {
+	StringFromClass :: proc(cls: Class) -> ^String ---
+}
 
 @(objc_type=String, objc_name="alloc", objc_is_class_method=true)
 String_alloc :: proc "c" () -> ^String {
@@ -73,7 +71,6 @@ String_init :: proc "c" (self: ^String) -> ^String {
 	return msgSend(^String, self, "init")
 }
 
-
 @(objc_type=String, objc_name="initWithString")
 String_initWithString :: proc "c" (self: ^String, other: ^String) -> ^String {
 	return msgSend(^String, self, "initWithString:", other)

+ 386 - 0
core/sys/darwin/Security/SecBase.odin

@@ -0,0 +1,386 @@
+package Security
+
+OSStatus :: distinct i32
+
+errSec :: enum OSStatus {
+	Success = 0, // No error.
+	Unimplemented = -4, // Function or operation not implemented.
+	DiskFull = -34, // The disk is full.
+	IO = -36, // I/O error.
+	OpWr = -49, // File already open with with write permission.
+	Param = -50, // One or more parameters passed to a function were not valid.
+	WrPerm = -61, // Write permissions error.
+	Allocate = -108, // Failed to allocate memory.
+	UserCanceled = -128, // User canceled the operation.
+	BadReq = -909, // Bad parameter or invalid state for operation.
+	InternalComponent = -2070,
+	CoreFoundationUnknown = -4960,
+	MissingEntitlement, // A required entitlement isn't present.
+	RestrictedAPI, // Client is restricted and is not permitted to perform this operation.
+	NotAvailable = -25291, // No keychain is available. You may need to restart your computer.
+	ReadOnly = -25292, // This keychain cannot be modified.
+	AuthFailed = -25293, // The user name or passphrase you entered is not correct.
+	NoSuchKeychain = -25294, // The specified keychain could not be found.
+	InvalidKeychain = -25295, // The specified keychain is not a valid keychain file.
+	DuplicateKeychain = -25296, // A keychain with the same name already exists.
+	DuplicateCallback = -25297, // The specified callback function is already installed.
+	InvalidCallback = -25298, // The specified callback function is not valid.
+	DuplicateItem = -25299, // The specified item already exists in the keychain.
+	ItemNotFound = -25300, // The specified item could not be found in the keychain.
+	BufferTooSmall = -25301, // There is not enough memory available to use the specified item.
+	DataTooLarge = -25302, // This item contains information which is too large or in a format that cannot be displayed.
+	NoSuchAttr = -25303, // The specified attribute does not exist.
+	InvalidItemRef = -25304, // The specified item is no longer valid. It may have been deleted from the keychain.
+	InvalidSearchRef = -25305, // Unable to search the current keychain.
+	NoSuchClass = -25306, // The specified item does not appear to be a valid keychain item.
+	NoDefaultKeychain = -25307, // A default keychain could not be found.
+	InteractionNotAllowed = -25308, // User interaction is not allowed.
+	ReadOnlyAttr = -25309, // The specified attribute could not be modified.
+	WrongSecVersion = -25310, // This keychain was created by a different version of the system software and cannot be opened.
+	KeySizeNotAllowed = -25311, // This item specifies a key size which is too large or too small.
+	NoStorageModule = -25312, // A required component (data storage module) could not be loaded. You may need to restart your computer.
+	NoCertificateModule = -25313, // A required component (certificate module) could not be loaded. You may need to restart your computer.
+	NoPolicyModule = -25314, // A required component (policy module) could not be loaded. You may need to restart your computer.
+	InteractionRequired = -25315, // User interaction is required, but is currently not allowed.
+	DataNotAvailable = -25316, // The contents of this item cannot be retrieved.
+	DataNotModifiable = -25317, // The contents of this item cannot be modified.
+	CreateChainFailed = -25318, // One or more certificates required to validate this certificate cannot be found.
+	InvalidPrefsDomain = -25319, // The specified preferences domain is not valid.
+	InDarkWake = -25320, // In dark wake, no UI possible
+	ACLNotSimple = -25240, // The specified access control list is not in standard (simple) form.
+	PolicyNotFound = -25241, // The specified policy cannot be found.
+	InvalidTrustSetting = -25242, // The specified trust setting is invalid.
+	NoAccessForItem = -25243, // The specified item has no access control.
+	InvalidOwnerEdit = -25244, // Invalid attempt to change the owner of this item.
+	TrustNotAvailable = -25245, // No trust results are available.
+	UnsupportedFormat = -25256, // Import/Export format unsupported.
+	UnknownFormat = -25257, // Unknown format in import.
+	KeyIsSensitive = -25258, // Key material must be wrapped for export.
+	MultiplePrivKeys = -25259, // An attempt was made to import multiple private keys.
+	PassphraseRequired = -25260, // Passphrase is required for import/export.
+	InvalidPasswordRef = -25261, // The password reference was invalid.
+	InvalidTrustSettings = -25262, // The Trust Settings Record was corrupted.
+	NoTrustSettings = -25263, // No Trust Settings were found.
+	Pkcs12VerifyFailure = -25264, // MAC verification failed during PKCS12 import (wrong password?)
+	NotSigner = -26267, // A certificate was not signed by its proposed parent.
+	Decode = -26275, // Unable to decode the provided data.
+	ServiceNotAvailable = -67585, // The required service is not available.
+	InsufficientClientID = -67586, // The client ID is not correct.
+	DeviceReset = -67587, // A device reset has occurred.
+	DeviceFailed = -67588, // A device failure has occurred.
+	AppleAddAppACLSubject = -67589, // Adding an application ACL subject failed.
+	ApplePublicKeyIncomplete = -67590, // The public key is incomplete.
+	AppleSignatureMismatch = -67591, // A signature mismatch has occurred.
+	AppleInvalidKeyStartDate = -67592, // The specified key has an invalid start date.
+	AppleInvalidKeyEndDate = -67593, // The specified key has an invalid end date.
+	ConversionError = -67594, // A conversion error has occurred.
+	AppleSSLv2Rollback = -67595, // A SSLv2 rollback error has occurred.
+	QuotaExceeded = -67596, // The quota was exceeded.
+	FileTooBig = -67597, // The file is too big.
+	InvalidDatabaseBlob = -67598, // The specified database has an invalid blob.
+	InvalidKeyBlob = -67599, // The specified database has an invalid key blob.
+	IncompatibleDatabaseBlob = -67600, // The specified database has an incompatible blob.
+	IncompatibleKeyBlob = -67601, // The specified database has an incompatible key blob.
+	HostNameMismatch = -67602, // A host name mismatch has occurred.
+	UnknownCriticalExtensionFlag = -67603, // There is an unknown critical extension flag.
+	NoBasicConstraints = -67604, // No basic constraints were found.
+	NoBasicConstraintsCA = -67605, // No basic CA constraints were found.
+	InvalidAuthorityKeyID = -67606, // The authority key ID is not valid.
+	InvalidSubjectKeyID = -67607, // The subject key ID is not valid.
+	InvalidKeyUsageForPolicy = -67608, // The key usage is not valid for the specified policy.
+	InvalidExtendedKeyUsage = -67609, // The extended key usage is not valid.
+	InvalidIDLinkage = -67610, // The ID linkage is not valid.
+	PathLengthConstraintExceeded = -67611, // The path length constraint was exceeded.
+	InvalidRoot = -67612, // The root or anchor certificate is not valid.
+	CRLExpired = -67613, // The CRL has expired.
+	CRLNotValidYet = -67614, // The CRL is not yet valid.
+	CRLNotFound = -67615, // The CRL was not found.
+	CRLServerDown = -67616, // The CRL server is down.
+	CRLBadURI = -67617, // The CRL has a bad Uniform Resource Identifier.
+	UnknownCertExtension = -67618, // An unknown certificate extension was encountered.
+	UnknownCRLExtension = -67619, // An unknown CRL extension was encountered.
+	CRLNotTrusted = -67620, // The CRL is not trusted.
+	CRLPolicyFailed = -67621, // The CRL policy failed.
+	IDPFailure = -67622, // The issuing distribution point was not valid.
+	SMIMEEmailAddressesNotFound = -67623, // An email address mismatch was encountered.
+	SMIMEBadExtendedKeyUsage = -67624, // The appropriate extended key usage for SMIME was not found.
+	SMIMEBadKeyUsage = -67625, // The key usage is not compatible with SMIME.
+	SMIMEKeyUsageNotCritical = -67626, // The key usage extension is not marked as critical.
+	SMIMENoEmailAddress = -67627, // No email address was found in the certificate.
+	SMIMESubjAltNameNotCritical = -67628, // The subject alternative name extension is not marked as critical.
+	SSLBadExtendedKeyUsage = -67629, // The appropriate extended key usage for SSL was not found.
+	OCSPBadResponse = -67630, // The OCSP response was incorrect or could not be parsed.
+	OCSPBadRequest = -67631, // The OCSP request was incorrect or could not be parsed.
+	OCSPUnavailable = -67632, // OCSP service is unavailable.
+	OCSPStatusUnrecognized = -67633, // The OCSP server did not recognize this certificate.
+	EndOfData = -67634, // An end-of-data was detected.
+	IncompleteCertRevocationCheck = -67635, // An incomplete certificate revocation check occurred.
+	NetworkFailure = -67636, // A network failure occurred.
+	OCSPNotTrustedToAnchor = -67637, // The OCSP response was not trusted to a root or anchor certificate.
+	RecordModified = -67638, // The record was modified.
+	OCSPSignatureError = -67639, // The OCSP response had an invalid signature.
+	OCSPNoSigner = -67640, // The OCSP response had no signer.
+	OCSPResponderMalformedReq = -67641, // The OCSP responder was given a malformed request.
+	OCSPResponderInternalError = -67642, // The OCSP responder encountered an internal error.
+	OCSPResponderTryLater = -67643, // The OCSP responder is busy, try again later.
+	OCSPResponderSignatureRequired = -67644, // The OCSP responder requires a signature.
+	OCSPResponderUnauthorized = -67645, // The OCSP responder rejected this request as unauthorized.
+	OCSPResponseNonceMismatch = -67646, // The OCSP response nonce did not match the request.
+	CodeSigningBadCertChainLength = -67647, // Code signing encountered an incorrect certificate chain length.
+	CodeSigningNoBasicConstraints = -67648, // Code signing found no basic constraints.
+	CodeSigningBadPathLengthConstraint = -67649, // Code signing encountered an incorrect path length constraint.
+	CodeSigningNoExtendedKeyUsage = -67650, // Code signing found no extended key usage.
+	CodeSigningDevelopment = -67651, // Code signing indicated use of a development-only certificate.
+	ResourceSignBadCertChainLength = -67652, // Resource signing has encountered an incorrect certificate chain length.
+	ResourceSignBadExtKeyUsage = -67653, // Resource signing has encountered an error in the extended key usage.
+	TrustSettingDeny = -67654, // The trust setting for this policy was set to Deny.
+	InvalidSubjectName = -67655, // An invalid certificate subject name was encountered.
+	UnknownQualifiedCertStatement = -67656, // An unknown qualified certificate statement was encountered.
+	MobileMeRequestQueued = -67657,
+	MobileMeRequestRedirected = -67658,
+	MobileMeServerError = -67659,
+	MobileMeServerNotAvailable = -67660,
+	MobileMeServerAlreadyExists = -67661,
+	MobileMeServerServiceErr = -67662,
+	MobileMeRequestAlreadyPending = -67663,
+	MobileMeNoRequestPending = -67664,
+	MobileMeCSRVerifyFailure = -67665,
+	MobileMeFailedConsistencyCheck = -67666,
+	NotInitialized = -67667, // A function was called without initializing CSSM.
+	InvalidHandleUsage = -67668, // The CSSM handle does not match with the service type.
+	PVCReferentNotFound = -67669, // A reference to the calling module was not found in the list of authorized callers.
+	FunctionIntegrityFail = -67670, // A function address was not within the verified module.
+	InternalError = -67671, // An internal error has occurred.
+	MemoryError = -67672, // A memory error has occurred.
+	InvalidData = -67673, // Invalid data was encountered.
+	MDSError = -67674, // A Module Directory Service error has occurred.
+	InvalidPointer = -67675, // An invalid pointer was encountered.
+	SelfCheckFailed = -67676, // Self-check has failed.
+	FunctionFailed = -67677, // A function has failed.
+	ModuleManifestVerifyFailed = -67678, // A module manifest verification failure has occurred.
+	InvalidGUID = -67679, // An invalid GUID was encountered.
+	InvalidHandle = -67680, // An invalid handle was encountered.
+	InvalidDBList = -67681, // An invalid DB list was encountered.
+	InvalidPassthroughID = -67682, // An invalid passthrough ID was encountered.
+	InvalidNetworkAddress = -67683, // An invalid network address was encountered.
+	CRLAlreadySigned = -67684, // The certificate revocation list is already signed.
+	InvalidNumberOfFields = -67685, // An invalid number of fields were encountered.
+	VerificationFailure = -67686, // A verification failure occurred.
+	UnknownTag = -67687, // An unknown tag was encountered.
+	InvalidSignature = -67688, // An invalid signature was encountered.
+	InvalidName = -67689, // An invalid name was encountered.
+	InvalidCertificateRef = -67690, // An invalid certificate reference was encountered.
+	InvalidCertificateGroup = -67691, // An invalid certificate group was encountered.
+	TagNotFound = -67692, // The specified tag was not found.
+	InvalidQuery = -67693, // The specified query was not valid.
+	InvalidValue = -67694, // An invalid value was detected.
+	CallbackFailed = -67695, // A callback has failed.
+	ACLDeleteFailed = -67696, // An ACL delete operation has failed.
+	ACLReplaceFailed = -67697, // An ACL replace operation has failed.
+	ACLAddFailed = -67698, // An ACL add operation has failed.
+	ACLChangeFailed = -67699, // An ACL change operation has failed.
+	InvalidAccessCredentials = -67700, // Invalid access credentials were encountered.
+	InvalidRecord = -67701, // An invalid record was encountered.
+	InvalidACL = -67702, // An invalid ACL was encountered.
+	InvalidSampleValue = -67703, // An invalid sample value was encountered.
+	IncompatibleVersion = -67704, // An incompatible version was encountered.
+	PrivilegeNotGranted = -67705, // The privilege was not granted.
+	InvalidScope = -67706, // An invalid scope was encountered.
+	PVCAlreadyConfigured = -67707, // The PVC is already configured.
+	InvalidPVC = -67708, // An invalid PVC was encountered.
+	EMMLoadFailed = -67709, // The EMM load has failed.
+	EMMUnloadFailed = -67710, // The EMM unload has failed.
+	AddinLoadFailed = -67711, // The add-in load operation has failed.
+	InvalidKeyRef = -67712, // An invalid key was encountered.
+	InvalidKeyHierarchy = -67713, // An invalid key hierarchy was encountered.
+	AddinUnloadFailed = -67714, // The add-in unload operation has failed.
+	LibraryReferenceNotFound = -67715, // A library reference was not found.
+	InvalidAddinFunctionTable = -67716, // An invalid add-in function table was encountered.
+	InvalidServiceMask = -67717, // An invalid service mask was encountered.
+	ModuleNotLoaded = -67718, // A module was not loaded.
+	InvalidSubServiceID = -67719, // An invalid subservice ID was encountered.
+	AttributeNotInContext = -67720, // An attribute was not in the context.
+	ModuleManagerInitializeFailed = -67721, // A module failed to initialize.
+	ModuleManagerNotFound = -67722, // A module was not found.
+	EventNotificationCallbackNotFound = -67723, // An event notification callback was not found.
+	InputLengthError = -67724, // An input length error was encountered.
+	OutputLengthError = -67725, // An output length error was encountered.
+	PrivilegeNotSupported = -67726, // The privilege is not supported.
+	DeviceError = -67727, // A device error was encountered.
+	AttachHandleBusy = -67728, // The CSP handle was busy.
+	NotLoggedIn = -67729, // You are not logged in.
+	AlgorithmMismatch = -67730, // An algorithm mismatch was encountered.
+	KeyUsageIncorrect = -67731, // The key usage is incorrect.
+	KeyBlobTypeIncorrect = -67732, // The key blob type is incorrect.
+	KeyHeaderInconsistent = -67733, // The key header is inconsistent.
+	UnsupportedKeyFormat = -67734, // The key header format is not supported.
+	UnsupportedKeySize = -67735, // The key size is not supported.
+	InvalidKeyUsageMask = -67736, // The key usage mask is not valid.
+	UnsupportedKeyUsageMask = -67737, // The key usage mask is not supported.
+	InvalidKeyAttributeMask = -67738, // The key attribute mask is not valid.
+	UnsupportedKeyAttributeMask = -67739, // The key attribute mask is not supported.
+	InvalidKeyLabel = -67740, // The key label is not valid.
+	UnsupportedKeyLabel = -67741, // The key label is not supported.
+	InvalidKeyFormat = -67742, // The key format is not valid.
+	UnsupportedVectorOfBuffers = -67743, // The vector of buffers is not supported.
+	InvalidInputVector = -67744, // The input vector is not valid.
+	InvalidOutputVector = -67745, // The output vector is not valid.
+	InvalidContext = -67746, // An invalid context was encountered.
+	InvalidAlgorithm = -67747, // An invalid algorithm was encountered.
+	InvalidAttributeKey = -67748, // A key attribute was not valid.
+	MissingAttributeKey = -67749, // A key attribute was missing.
+	InvalidAttributeInitVector = -67750, // An init vector attribute was not valid.
+	MissingAttributeInitVector = -67751, // An init vector attribute was missing.
+	InvalidAttributeSalt = -67752, // A salt attribute was not valid.
+	MissingAttributeSalt = -67753, // A salt attribute was missing.
+	InvalidAttributePadding = -67754, // A padding attribute was not valid.
+	MissingAttributePadding = -67755, // A padding attribute was missing.
+	InvalidAttributeRandom = -67756, // A random number attribute was not valid.
+	MissingAttributeRandom = -67757, // A random number attribute was missing.
+	InvalidAttributeSeed = -67758, // A seed attribute was not valid.
+	MissingAttributeSeed = -67759, // A seed attribute was missing.
+	InvalidAttributePassphrase = -67760, // A passphrase attribute was not valid.
+	MissingAttributePassphrase = -67761, // A passphrase attribute was missing.
+	InvalidAttributeKeyLength = -67762, // A key length attribute was not valid.
+	MissingAttributeKeyLength = -67763, // A key length attribute was missing.
+	InvalidAttributeBlockSize = -67764, // A block size attribute was not valid.
+	MissingAttributeBlockSize = -67765, // A block size attribute was missing.
+	InvalidAttributeOutputSize = -67766, // An output size attribute was not valid.
+	MissingAttributeOutputSize = -67767, // An output size attribute was missing.
+	InvalidAttributeRounds = -67768, // The number of rounds attribute was not valid.
+	MissingAttributeRounds = -67769, // The number of rounds attribute was missing.
+	InvalidAlgorithmParms = -67770, // An algorithm parameters attribute was not valid.
+	MissingAlgorithmParms = -67771, // An algorithm parameters attribute was missing.
+	InvalidAttributeLabel = -67772, // A label attribute was not valid.
+	MissingAttributeLabel = -67773, // A label attribute was missing.
+	InvalidAttributeKeyType = -67774, // A key type attribute was not valid.
+	MissingAttributeKeyType = -67775, // A key type attribute was missing.
+	InvalidAttributeMode = -67776, // A mode attribute was not valid.
+	MissingAttributeMode = -67777, // A mode attribute was missing.
+	InvalidAttributeEffectiveBits = -67778, // An effective bits attribute was not valid.
+	MissingAttributeEffectiveBits = -67779, // An effective bits attribute was missing.
+	InvalidAttributeStartDate = -67780, // A start date attribute was not valid.
+	MissingAttributeStartDate = -67781, // A start date attribute was missing.
+	InvalidAttributeEndDate = -67782, // An end date attribute was not valid.
+	MissingAttributeEndDate = -67783, // An end date attribute was missing.
+	InvalidAttributeVersion = -67784, // A version attribute was not valid.
+	MissingAttributeVersion = -67785, // A version attribute was missing.
+	InvalidAttributePrime = -67786, // A prime attribute was not valid.
+	MissingAttributePrime = -67787, // A prime attribute was missing.
+	InvalidAttributeBase = -67788, // A base attribute was not valid.
+	MissingAttributeBase = -67789, // A base attribute was missing.
+	InvalidAttributeSubprime = -67790, // A subprime attribute was not valid.
+	MissingAttributeSubprime = -67791, // A subprime attribute was missing.
+	InvalidAttributeIterationCount = -67792, // An iteration count attribute was not valid.
+	MissingAttributeIterationCount = -67793, // An iteration count attribute was missing.
+	InvalidAttributeDLDBHandle = -67794, // A database handle attribute was not valid.
+	MissingAttributeDLDBHandle = -67795, // A database handle attribute was missing.
+	InvalidAttributeAccessCredentials = -67796, // An access credentials attribute was not valid.
+	MissingAttributeAccessCredentials = -67797, // An access credentials attribute was missing.
+	InvalidAttributePublicKeyFormat = -67798, // A public key format attribute was not valid.
+	MissingAttributePublicKeyFormat = -67799, // A public key format attribute was missing.
+	InvalidAttributePrivateKeyFormat = -67800, // A private key format attribute was not valid.
+	MissingAttributePrivateKeyFormat = -67801, // A private key format attribute was missing.
+	InvalidAttributeSymmetricKeyFormat = -67802, // A symmetric key format attribute was not valid.
+	MissingAttributeSymmetricKeyFormat = -67803, // A symmetric key format attribute was missing.
+	InvalidAttributeWrappedKeyFormat = -67804, // A wrapped key format attribute was not valid.
+	MissingAttributeWrappedKeyFormat = -67805, // A wrapped key format attribute was missing.
+	StagedOperationInProgress = -67806, // A staged operation is in progress.
+	StagedOperationNotStarted = -67807, // A staged operation was not started.
+	VerifyFailed = -67808, // A cryptographic verification failure has occurred.
+	QuerySizeUnknown = -67809, // The query size is unknown.
+	BlockSizeMismatch = -67810, // A block size mismatch occurred.
+	PublicKeyInconsistent = -67811, // The public key was inconsistent.
+	DeviceVerifyFailed = -67812, // A device verification failure has occurred.
+	InvalidLoginName = -67813, // An invalid login name was detected.
+	AlreadyLoggedIn = -67814, // The user is already logged in.
+	InvalidDigestAlgorithm = -67815, // An invalid digest algorithm was detected.
+	InvalidCRLGroup = -67816, // An invalid CRL group was detected.
+	CertificateCannotOperate = -67817, // The certificate cannot operate.
+	CertificateExpired = -67818, // An expired certificate was detected.
+	CertificateNotValidYet = -67819, // The certificate is not yet valid.
+	CertificateRevoked = -67820, // The certificate was revoked.
+	CertificateSuspended = -67821, // The certificate was suspended.
+	InsufficientCredentials = -67822, // Insufficient credentials were detected.
+	InvalidAction = -67823, // The action was not valid.
+	InvalidAuthority = -67824, // The authority was not valid.
+	VerifyActionFailed = -67825, // A verify action has failed.
+	InvalidCertAuthority = -67826, // The certificate authority was not valid.
+	InvalidCRLAuthority = -67827, // The CRL authority was not valid.
+	InvalidCRLEncoding = -67828, // The CRL encoding was not valid.
+	InvalidCRLType = -67829, // The CRL type was not valid.
+	InvalidCRL = -67830, // The CRL was not valid.
+	InvalidFormType = -67831, // The form type was not valid.
+	InvalidID = -67832, // The ID was not valid.
+	InvalidIdentifier = -67833, // The identifier was not valid.
+	InvalidIndex = -67834, // The index was not valid.
+	InvalidPolicyIdentifiers = -67835, // The policy identifiers are not valid.
+	InvalidTimeString = -67836, // The time specified was not valid.
+	InvalidReason = -67837, // The trust policy reason was not valid.
+	InvalidRequestInputs = -67838, // The request inputs are not valid.
+	InvalidResponseVector = -67839, // The response vector was not valid.
+	InvalidStopOnPolicy = -67840, // The stop-on policy was not valid.
+	InvalidTuple = -67841, // The tuple was not valid.
+	MultipleValuesUnsupported = -67842, // Multiple values are not supported.
+	NotTrusted = -67843, // The certificate was not trusted.
+	NoDefaultAuthority = -67844, // No default authority was detected.
+	RejectedForm = -67845, // The trust policy had a rejected form.
+	RequestLost = -67846, // The request was lost.
+	RequestRejected = -67847, // The request was rejected.
+	UnsupportedAddressType = -67848, // The address type is not supported.
+	UnsupportedService = -67849, // The service is not supported.
+	InvalidTupleGroup = -67850, // The tuple group was not valid.
+	InvalidBaseACLs = -67851, // The base ACLs are not valid.
+	InvalidTupleCredentials = -67852, // The tuple credentials are not valid.
+	InvalidEncoding = -67853, // The encoding was not valid.
+	InvalidValidityPeriod = -67854, // The validity period was not valid.
+	InvalidRequestor = -67855, // The requestor was not valid.
+	RequestDescriptor = -67856, // The request descriptor was not valid.
+	InvalidBundleInfo = -67857, // The bundle information was not valid.
+	InvalidCRLIndex = -67858, // The CRL index was not valid.
+	NoFieldValues = -67859, // No field values were detected.
+	UnsupportedFieldFormat = -67860, // The field format is not supported.
+	UnsupportedIndexInfo = -67861, // The index information is not supported.
+	UnsupportedLocality = -67862, // The locality is not supported.
+	UnsupportedNumAttributes = -67863, // The number of attributes is not supported.
+	UnsupportedNumIndexes = -67864, // The number of indexes is not supported.
+	UnsupportedNumRecordTypes = -67865, // The number of record types is not supported.
+	FieldSpecifiedMultiple = -67866, // Too many fields were specified.
+	IncompatibleFieldFormat = -67867, // The field format was incompatible.
+	InvalidParsingModule = -67868, // The parsing module was not valid.
+	DatabaseLocked = -67869, // The database is locked.
+	DatastoreIsOpen = -67870, // The data store is open.
+	MissingValue = -67871, // A missing value was detected.
+	UnsupportedQueryLimits = -67872, // The query limits are not supported.
+	UnsupportedNumSelectionPreds = -67873, // The number of selection predicates is not supported.
+	UnsupportedOperator = -67874, // The operator is not supported.
+	InvalidDBLocation = -67875, // The database location is not valid.
+	InvalidAccessRequest = -67876, // The access request is not valid.
+	InvalidIndexInfo = -67877, // The index information is not valid.
+	InvalidNewOwner = -67878, // The new owner is not valid.
+	InvalidModifyMode = -67879, // The modify mode is not valid.
+	MissingRequiredExtension = -67880, // A required certificate extension is missing.
+	ExtendedKeyUsageNotCritical = -67881, // The extended key usage extension was not marked critical.
+	TimestampMissing = -67882, // A timestamp was expected but was not found.
+	TimestampInvalid = -67883, // The timestamp was not valid.
+	TimestampNotTrusted = -67884, // The timestamp was not trusted.
+	TimestampServiceNotAvailable = -67885, // The timestamp service is not available.
+	TimestampBadAlg = -67886, // An unrecognized or unsupported Algorithm Identifier in timestamp.
+	TimestampBadRequest = -67887, // The timestamp transaction is not permitted or supported.
+	TimestampBadDataFormat = -67888, // The timestamp data submitted has the wrong format.
+	TimestampTimeNotAvailable = -67889, // The time source for the Timestamp Authority is not available.
+	TimestampUnacceptedPolicy = -67890, // The requested policy is not supported by the Timestamp Authority.
+	TimestampUnacceptedExtension = -67891, // The requested extension is not supported by the Timestamp Authority.
+	TimestampAddInfoNotAvailable = -67892, // The additional information requested is not available.
+	TimestampSystemFailure = -67893, // The timestamp request cannot be handled due to system failure.
+	SigningTimeMissing = -67894, // A signing time was expected but was not found.
+	TimestampRejection = -67895, // A timestamp transaction was rejected.
+	TimestampWaiting = -67896, // A timestamp transaction is waiting.
+	TimestampRevocationWarning = -67897, // A timestamp authority revocation warning was issued.
+	TimestampRevocationNotification = -67898, // A timestamp authority revocation notification was issued.
+	CertificatePolicyNotAllowed = -67899, // The requested policy is not allowed for this certificate.
+	CertificateNameNotAllowed = -67900, // The requested name is not allowed for this certificate.
+	CertificateValidityPeriodTooLong = -67901, // The validity period in the certificate exceeds the maximum allowed.
+	CertificateIsCA = -67902, // The verified certificate is a CA rather than an end-entity.
+	CertificateDuplicateExtension = -67903, // The certificate contains multiple extensions with the same extension ID.
+}

+ 19 - 0
core/sys/darwin/Security/SecRandom.odin

@@ -0,0 +1,19 @@
+package Security
+
+import CF "core:sys/darwin/CoreFoundation"
+
+foreign import Security "system:Security.framework"
+
+// A reference to a random number generator.
+RandomRef :: distinct rawptr
+
+@(link_prefix="Sec", default_calling_convention="c")
+foreign Security {
+	// Default random ref for /dev/random. Synonym for nil.
+	@(link_name="kSecRandomDefault") kSecRandomDefault: RandomRef
+
+	// Generates an array of cryptographically secure random bytes.
+	RandomCopyBytes :: proc(rnd: RandomRef = kSecRandomDefault, count: uint, bytes: [^]byte) -> errSec ---
+
+	CopyErrorMessageString :: proc(status: errSec, reserved: rawptr = nil) -> CF.String ---
+}

+ 0 - 98
core/sys/darwin/core_foundation.odin

@@ -1,98 +0,0 @@
-//+build darwin
-package darwin
-
-import "base:runtime"
-
-foreign import core_foundation "system:CoreFoundation.framework"
-
-CFTypeRef   :: distinct rawptr
-
-CFStringRef :: distinct CFTypeRef
-
-CFIndex :: int
-
-CFRange :: struct {
-	location: CFIndex,
-	length:   CFIndex,
-}
-
-CFStringEncoding :: enum u32 {
-	ASCII             = 1,
-	NEXTSTEP          = 2,
-	JapaneseEUC       = 3,
-	UTF8              = 4,
-	ISOLatin1         = 5,
-	Symbol            = 6,
-	NonLossyASCII     = 7,
-	ShiftJIS          = 8,
-	ISOLatin2         = 9,
-	Unicode           = 10,
-	WindowsCP1251     = 11,
-	WindowsCP1252     = 12,
-	WindowsCP1253     = 13,
-	WindowsCP1254     = 14,
-	WindowsCP1250     = 15,
-	ISO2022JP         = 21,
-	MacOSRoman        = 30,
-
-	UTF16             = Unicode,
-
-	UTF16BigEndian    = 0x90000100,
-	UTF16LittleEndian = 0x94000100,
-
-	UTF32             = 0x8c000100,
-	UTF32BigEndian    = 0x98000100,
-	UTF32LittleEndian = 0x9c000100,
-}
-
-foreign core_foundation {
-	// Copies the character contents of a string to a local C string buffer after converting the characters to a given encoding.
-	CFStringGetCString :: proc(theString: CFStringRef, buffer: [^]byte, bufferSize: CFIndex, encoding: CFStringEncoding) -> Bool ---
-	
-	// Returns the number (in terms of UTF-16 code pairs) of Unicode characters in a string.
-	CFStringGetLength :: proc(theString: CFStringRef) -> CFIndex ---
-	
-	// Returns the maximum number of bytes a string of a specified length (in Unicode characters) will take up if encoded in a specified encoding.
-	CFStringGetMaximumSizeForEncoding :: proc(length: CFIndex, encoding: CFStringEncoding) -> CFIndex ---
-	
-	// Fetches a range of the characters from a string into a byte buffer after converting the characters to a specified encoding.
-	CFStringGetBytes :: proc(
-		thestring: CFStringRef,
-		range: CFRange,
-		encoding: CFStringEncoding,
-		lossByte: u8,
-		isExternalRepresentation: Bool,
-		buffer: [^]byte,
-		maxBufLen: CFIndex,
-		usedBufLen: ^CFIndex,
-	) -> CFIndex ---
-	
-	// Releases a Core Foundation object.
-	@(link_name="CFRelease")
-	_CFRelease :: proc(cf: CFTypeRef) ---
-}
-
-// Releases a Core Foundation object.
-CFRelease :: proc {
-	CFReleaseString,
-}
-
-// Releases a Core Foundation string.
-CFReleaseString :: #force_inline proc(theString: CFStringRef) {
-	_CFRelease(CFTypeRef(theString))
-}
-
-CFStringCopyToOdinString :: proc(theString: CFStringRef, allocator := context.allocator) -> (str: string, ok: bool) #optional_ok {
-	length := CFStringGetLength(theString)
-	max    := CFStringGetMaximumSizeForEncoding(length, .UTF8)
-
-	buf, err := make([]byte, max, allocator)
-	if err != nil { return }
-	
-	raw_str := runtime.Raw_String{
-		data = raw_data(buf),
-	}
-	CFStringGetBytes(theString, {0, length}, .UTF8, 0, false, raw_data(buf), max, &raw_str.len)
-
-	return transmute(string)raw_str, true
-}

+ 0 - 26
core/sys/darwin/security.odin

@@ -1,26 +0,0 @@
-//+build darwin
-package darwin
-
-foreign import security "system:Security.framework"
-
-// A reference to a random number generator.
-SecRandomRef :: distinct rawptr
-
-OSStatus :: distinct i32
-
-errSec :: enum OSStatus {
-	Success       = 0,  // No error.
-	Unimplemented = -4, // Function or operation not implemented.
-
-	// Many more...
-}
-
-foreign security {
-	// Synonym for nil, uses a cryptographically secure random number generator.
-	kSecRandomDefault: SecRandomRef
-	
-	// Generates an array of cryptographically secure random bytes.
-	SecRandomCopyBytes :: proc(rnd: SecRandomRef = kSecRandomDefault, count: uint, bytes: [^]byte) -> errSec ---
-
-	SecCopyErrorMessageString :: proc(status: errSec, reserved: rawptr = nil) -> CFStringRef ---
-}

+ 1 - 1
examples/demo/demo.odin

@@ -7,7 +7,7 @@ import "core:os"
 import "core:thread"
 import "core:time"
 import "core:reflect"
-import "core:runtime"
+import "base:runtime"
 import "core:intrinsics"
 import "core:math/big"