// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build darwin,!ios

// Package macOS provides cgo-less wrappers for Core Foundation and // Security.framework, similarly to how package syscall provides access to // libSystem.dylib.
package macOS import ( ) // Core Foundation linker flags for the external linker. See Issue 42459. //go:cgo_ldflag "-framework" //go:cgo_ldflag "CoreFoundation" // CFRef is an opaque reference to a Core Foundation object. It is a pointer, // but to memory not owned by Go, so not an unsafe.Pointer. type CFRef uintptr // CFDataToSlice returns a copy of the contents of data as a bytes slice. func ( CFRef) []byte { := CFDataGetLength() := CFDataGetBytePtr() := (*[1 << 20]byte)(unsafe.Pointer())[::] := make([]byte, ) copy(, ) return } type CFString CFRef const kCFAllocatorDefault = 0 const kCFStringEncodingUTF8 = 0x08000100 //go:linkname x509_CFStringCreateWithBytes x509_CFStringCreateWithBytes //go:cgo_import_dynamic x509_CFStringCreateWithBytes CFStringCreateWithBytes "/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation" // StringToCFString returns a copy of the UTF-8 contents of s as a new CFString. func ( string) CFString { := unsafe.Pointer((*reflect.StringHeader)(unsafe.Pointer(&)).Data) := syscall(funcPC(x509_CFStringCreateWithBytes_trampoline), kCFAllocatorDefault, uintptr(), uintptr(len()), uintptr(kCFStringEncodingUTF8), 0 /* isExternalRepresentation */, 0) runtime.KeepAlive() return CFString() } func () //go:linkname x509_CFDictionaryGetValueIfPresent x509_CFDictionaryGetValueIfPresent //go:cgo_import_dynamic x509_CFDictionaryGetValueIfPresent CFDictionaryGetValueIfPresent "/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation" func ( CFRef, CFString) ( CFRef, bool) { := syscall(funcPC(x509_CFDictionaryGetValueIfPresent_trampoline), uintptr(), uintptr(), uintptr(unsafe.Pointer(&)), 0, 0, 0) if == 0 { return 0, false } return , true } func () const kCFNumberSInt32Type = 3 //go:linkname x509_CFNumberGetValue x509_CFNumberGetValue //go:cgo_import_dynamic x509_CFNumberGetValue CFNumberGetValue "/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation" func ( CFRef) (int32, error) { var int32 := syscall(funcPC(x509_CFNumberGetValue_trampoline), uintptr(), uintptr(kCFNumberSInt32Type), uintptr(unsafe.Pointer(&)), 0, 0, 0) if == 0 { return 0, errors.New("CFNumberGetValue call failed") } return , nil } func () //go:linkname x509_CFDataGetLength x509_CFDataGetLength //go:cgo_import_dynamic x509_CFDataGetLength CFDataGetLength "/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation" func ( CFRef) int { := syscall(funcPC(x509_CFDataGetLength_trampoline), uintptr(), 0, 0, 0, 0, 0) return int() } func () //go:linkname x509_CFDataGetBytePtr x509_CFDataGetBytePtr //go:cgo_import_dynamic x509_CFDataGetBytePtr CFDataGetBytePtr "/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation" func ( CFRef) uintptr { := syscall(funcPC(x509_CFDataGetBytePtr_trampoline), uintptr(), 0, 0, 0, 0, 0) return } func () //go:linkname x509_CFArrayGetCount x509_CFArrayGetCount //go:cgo_import_dynamic x509_CFArrayGetCount CFArrayGetCount "/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation" func ( CFRef) int { := syscall(funcPC(x509_CFArrayGetCount_trampoline), uintptr(), 0, 0, 0, 0, 0) return int() } func () //go:linkname x509_CFArrayGetValueAtIndex x509_CFArrayGetValueAtIndex //go:cgo_import_dynamic x509_CFArrayGetValueAtIndex CFArrayGetValueAtIndex "/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation" func ( CFRef, int) CFRef { := syscall(funcPC(x509_CFArrayGetValueAtIndex_trampoline), uintptr(), uintptr(), 0, 0, 0, 0) return CFRef() } func () //go:linkname x509_CFEqual x509_CFEqual //go:cgo_import_dynamic x509_CFEqual CFEqual "/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation" func (, CFRef) bool { := syscall(funcPC(x509_CFEqual_trampoline), uintptr(), uintptr(), 0, 0, 0, 0) return == 1 } func () //go:linkname x509_CFRelease x509_CFRelease //go:cgo_import_dynamic x509_CFRelease CFRelease "/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation" func ( CFRef) { syscall(funcPC(x509_CFRelease_trampoline), uintptr(), 0, 0, 0, 0, 0) } func () // syscall is implemented in the runtime package (runtime/sys_darwin.go) func (, , , , , , uintptr) uintptr // funcPC returns the entry point for f. See comments in runtime/proc.go // for the function of the same name. //go:nosplit func ( func()) uintptr { return **(**uintptr)(unsafe.Pointer(&)) }