github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/crypto/x509/internal/macos/corefoundation.go (about)

     1  // Copyright 2020 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build darwin
     6  
     7  // Package macOS provides cgo-less wrappers for Core Foundation and
     8  // Security.framework, similarly to how package syscall provides access to
     9  // libSystem.dylib.
    10  package macOS
    11  
    12  import (
    13  	"github.com/shogo82148/std/time"
    14  )
    15  
    16  // CFRef is an opaque reference to a Core Foundation object. It is a pointer,
    17  // but to memory not owned by Go, so not an unsafe.Pointer.
    18  type CFRef uintptr
    19  
    20  // CFDataToSlice returns a copy of the contents of data as a bytes slice.
    21  func CFDataToSlice(data CFRef) []byte
    22  
    23  // CFStringToString returns a Go string representation of the passed
    24  // in CFString, or an empty string if it's invalid.
    25  func CFStringToString(ref CFRef) string
    26  
    27  // TimeToCFDateRef converts a time.Time into an apple CFDateRef.
    28  func TimeToCFDateRef(t time.Time) CFRef
    29  
    30  type CFString CFRef
    31  
    32  func BytesToCFData(b []byte) CFRef
    33  
    34  // StringToCFString returns a copy of the UTF-8 contents of s as a new CFString.
    35  func StringToCFString(s string) CFString
    36  
    37  func CFDictionaryGetValueIfPresent(dict CFRef, key CFString) (value CFRef, ok bool)
    38  
    39  func CFNumberGetValue(num CFRef) (int32, error)
    40  
    41  func CFDataGetLength(data CFRef) int
    42  
    43  func CFDataGetBytePtr(data CFRef) uintptr
    44  
    45  func CFArrayGetCount(array CFRef) int
    46  
    47  func CFArrayGetValueAtIndex(array CFRef, index int) CFRef
    48  
    49  func CFEqual(a, b CFRef) bool
    50  
    51  func CFRelease(ref CFRef)
    52  
    53  func CFArrayCreateMutable() CFRef
    54  
    55  func CFArrayAppendValue(array CFRef, val CFRef)
    56  
    57  func CFDateCreate(seconds float64) CFRef
    58  
    59  func CFErrorCopyDescription(errRef CFRef) CFRef
    60  
    61  func CFErrorGetCode(errRef CFRef) int
    62  
    63  func CFStringCreateExternalRepresentation(strRef CFRef) (CFRef, error)
    64  
    65  // ReleaseCFArray iterates through an array, releasing its contents, and then
    66  // releases the array itself. This is necessary because we cannot, easily, set the
    67  // CFArrayCallBacks argument when creating CFArrays.
    68  func ReleaseCFArray(array CFRef)