[英]Crypto++ causing application failure
I am developing an AIR Native Extension of Crypto++ for Flash which I will release as public domain. 我正在开发一个Crypto ++ for Flash的AIR Native Extension,我将作为公共域发布。 I started with some code to test hashing (with SHA-256 in this case) but for some reason
CryptoPP::SHA256().CalculateDigest(abDigest, pbData, nDataLen);
我开始使用一些代码来测试散列(在这种情况下使用SHA-256),但由于某种原因,
CryptoPP::SHA256().CalculateDigest(abDigest, pbData, nDataLen);
(as discovered by the process of elimination) causes the Flash compiler to not recognize any available methods (The extension context does not have a method with the name isSupported.): (由消除过程发现)导致Flash编译器无法识别任何可用的方法(扩展上下文没有名称为isSupported的方法):
Here's the full C++ code: 这是完整的C ++代码:
FREObject isSupported(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
{
FREObject result;
uint32_t isSupportedSwitch = 1;
FRENewObjectFromBool(isSupportedSwitch, &result);
return result;
}
FREObject computeHash(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
{
FREObject result;
FREByteArray actualBytes;
FREAcquireByteArray(argv[0], &actualBytes);
byte const* pbData = (byte*) actualBytes.bytes;
unsigned int nDataLen = strlen((const char*) pbData);
byte abDigest[CryptoPP::SHA256::DIGESTSIZE];
CryptoPP::SHA256().CalculateDigest(abDigest, pbData, nDataLen);
memcpy(actualBytes.bytes, (uint8_t*) abDigest, 32);
FREReleaseByteArray(argv[0]);
FRENewObjectFromBool(1, &result);
return result;
}
void testContextInitializer(void* extData, const uint8_t* ctxType, FREContext ctx, uint32_t* numFunctions, const FRENamedFunction** functions)
{
*numFunctions = 2;
FRENamedFunction* func = (FRENamedFunction*) malloc(sizeof(FRENamedFunction) * (*numFunctions));
func[0].name = (const uint8_t*) "isSupported";
func[0].functionData = NULL;
func[0].function = &isSupported;
func[1].name = (const uint8_t*) "computeHash";
func[1].functionData = NULL;
func[1].function = &computeHash;
*functions = func;
}
void testContextFinalizer(FREContext ctx)
{
return;
}
void testInitializer(void** extData, FREContextInitializer* ctxInitializer, FREContextFinalizer* ctxFinalizer)
{
*ctxInitializer = &testContextInitializer;
*ctxFinalizer = &testContextFinalizer;
}
void testFinalizer(void* extData)
{
return;
}
Any help on this would be deeply appreciated and would go a long way in helping me in this project. 对此的任何帮助都将深表感谢,并将在帮助我完成这个项目方面有很长的路要走。
EDIT: To clarify, I am asking why CryptoPP::SHA256().CalculateDigest(abDigest, pbData, nDataLen);
编辑:澄清一下,我问为什么
CryptoPP::SHA256().CalculateDigest(abDigest, pbData, nDataLen);
causes the application failure mentioned above and possible ways to fix it. 导致上面提到的应用程序失败以及修复它的可能方法。
It looks like you're assuming that actualBytes.bytes is a pointer to a block of memory that is at least 32 bytes, since you've hard-coded 32 as the third argument in memcpy. 看起来你假设actualBytes.bytes是一个至少32字节的内存块的指针,因为你已经硬编码32作为memcpy中的第三个参数。
This is probably an invalid assumption and you should check to make sure that actualBytes.length >= 32 before performing the memcpy 这可能是一个无效的假设,您应该在执行memcpy之前检查以确保actualBytes.length> = 32
The safest approach might be to ensure that you've allocated a sufficiently large block of memory from the ActionScript side. 最安全的方法可能是确保从ActionScript端分配了足够大的内存块。 Alternatively you could try allocating memory in C++ and then modifying the actualBytes contents to point to that allocation and change the length value.
或者,您可以尝试在C ++中分配内存,然后修改actualBytes内容以指向该分配并更改长度值。 But this definitely seems frought with dangers.
但这肯定似乎充满了危险。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.