我正在使用D并与一些C库连接.因此,我必须将D数组转换为C的指针(例如short*).目前我只是像这样投射他们:
int[] dArray = [0, 1, 2, 3, 4];
myCFunction(cast(int*) dArray);
Run Code Online (Sandbox Code Playgroud)
这不安全吗?我试着这样做:
myCFunction(&dArray);
Run Code Online (Sandbox Code Playgroud)
但这样做会给函数一个int []*而不是int*.我看到在C++中有些人采用这样的第一个元素:
myCFunction(&dArray[0]);
Run Code Online (Sandbox Code Playgroud)
但是那个指针不会只指向第一个元素吗?因为我来自Java世界,所以我不熟悉指针和参考.
如何将数组转换为指针,以便将其传递给C函数?
我使用 OpenSSL 生成了一个椭圆曲线私钥/公钥对。私钥和公钥是 PEM 编码的。由于这个,我已经想出了如何加载公钥。但是,我不知道如何加载私钥,因为上面的消息只是以 InvalidKeySpecException: key spec notknowledge 结束。
然后我找到了this,但它也以“无法识别的编码密钥规范”告终。如何加载我的私钥?
private PrivateKey loadPrivateKey(String location) {
try {
// Strip the guarding strings
byte[] bytes = stripGuardLines(location);
return KeyFactory.getInstance("ECDH").generatePrivate(new PKCS8EncodedKeySpec(bytes));
} catch (FileNotFoundException e) {
LoggerFactory.getLogger("Nectar").error("Failed to find Private KEY: " + location);
System.exit(1);
} catch (IOException e) {
LoggerFactory.getLogger("Nectar").error("IOException while loading Private Key!");
e.printStackTrace();
System.exit(1);
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
e.printStackTrace();
System.exit(1);
}
return null;
}
private byte[] stripGuardLines(String location) throws …Run Code Online (Sandbox Code Playgroud) 我有一个非常奇怪的问题.我有一个if语句,如下所示:
$rootScope.changeView = function(view){
$location.path(view); // path not hash
};
$rootScope.$on('$routeChangeStart', function (event, next) {
console.log(next.requireLogin + " " + LoginService.getUserLoggedIn());
console.log(next.requireLogin && !LoginService.getUserLoggedIn());
if(next.requireLogin && !LoginService.getUserLoggedIn()) {
console.log("No access to panel: not logged in.");
alert("You need to be logged in as an administrator to see this page!");
event.preventDefault();
$timeout(function () {
$rootScope.changeView("/");
}, 500);
}
});
Run Code Online (Sandbox Code Playgroud)
LoginServer.getUserLoggedIn和setUserLoggedIn是这样的:
this.setUserLoggedIn = function(value){
sessionStorage.userIsLoggedIn = value;
};
this.getUserLoggedIn = function() {
return sessionStorage.userIsLoggedIn;
};
Run Code Online (Sandbox Code Playgroud)
问题很简单.永远不会调用If语句,即使next.requireLogin为true且LoginService.getUserLoggedIn()为false.控制台中的输出如下:
true false
false
Run Code Online (Sandbox Code Playgroud)
显然"next.requireLogin &&!LoginService.getUserLoggedIn()"的计算结果为false,但两者都是正确的值?如果有帮助,在Chrome控制台中,带有"false"的最后一行会突出显示为紫色.
有谁知道什么是错的?
angularjs ×1
arrays ×1
bouncycastle ×1
c ×1
cryptography ×1
d ×1
if-statement ×1
java ×1
javascript ×1
pointers ×1
private-key ×1