gpt4 book ai didi

objective-c - SecKeychainGetPath 错误

转载 作者:行者123 更新时间:2023-12-01 12:59:02 26 4
gpt4 key购买 nike

有时,在尝试获取 SecKeychainCopySearchList 返回的钥匙串(keychain)的路径时,我会收到代码 -25301 的错误,错误列表中的代码代表 errSecBufferTooSmallSecCopyErrorMessageString 声明:

There is not enough memory available to use the specified item.

奇怪的是,它并不总是在同一个钥匙串(keychain)引用上返回错误。

以下是我尝试获取钥匙串(keychain)路径的方法:

- (NSString *)getKeychainPath:(SecKeychainRef)keychain {
char *pathName = malloc(sizeof(*pathName) * 1024);
UInt32 pathLength;
OSStatus errCode = SecKeychainGetPath(keychain, &pathLength, pathName);
if (errCode != errSecSuccess) {
NSString *errString = (NSString *)SecCopyErrorMessageString(errCode, NULL);
DLog(@"%d: %@", errCode, errString);
}
NSData *d = [NSData dataWithBytes:pathName length:pathLength];
return [[[NSString alloc] initWithData:d encoding:NSUTF8StringEncoding] autorelease];
}

我对函数使用什么缓冲区感兴趣?我试过输出 pathLength 变量,但它低于 1K 字节。我究竟做错了什么?我应该怎么做才能避免这些错误?是否可以通过任何方式绕过它们?

最佳答案

来自SecKeychainGetPath documentation :

ioPathLength

On entry, a pointer to a variable containing the length (in bytes) of the buffer specified by pathName.
On return, the string length of pathName, not including the null termination.

您没有执行“输入时”部分。您需要将 pathLength 初始化为 pathName 缓冲区的大小。例如:

UInt32 pathLength = 1024;
char *pathName = malloc(pathLength);

关于objective-c - SecKeychainGetPath 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7861203/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com