小编Ric*_*ich的帖子

如何验证gpg签名是否与公钥文件匹配?

我知道如何使用gpg验证这样:

$ gpg --verify somefile.sig
gpg: Signature made Tue 23 Jul 2013 13:20:02 BST using RSA key ID E1B768A0
gpg: Good signature from "Richard W.M. Jones <rjones@redhat.com>"
gpg:                 aka "Richard W.M. Jones <rich@annexia.org>"
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: F777 4FB1 AD07 4A7E 8C87  67EA 9173 8F73 E1B7 68A0
Run Code Online (Sandbox Code Playgroud)

但我真正想要做的是根据特定的公钥文件验证文件.

动机是从网站下载大文件并需要验证它们在使用之前没有被篡改的程序的一部分.该网站将包含文件和签名.该程序将附带GPG公钥.当我将文件上传到网站时,我将使用相应的私钥对其进行签名(显然不会分发).似乎该程序应该能够执行以下操作:

gpg --no-default-keyring --verify file.sig \
    --is-signed-with /usr/share/program/goodkey.asc
Run Code Online (Sandbox Code Playgroud)

但是gpg …

gnupg openpgp

28
推荐指数
2
解决办法
5万
查看次数

如何为包含可为空函数指针的 FFI 创建结构?

我有一个加载共享库插件的现有 C 程序。主 C 程序通过包含整数、字符串、函数指针等的 C 结构与这些插件交互。如何从 Rust 创建这样的插件?

请注意,(真实的)C 程序不能更改,API 也不能更改,那些是固定的、现有的东西,所以这不是关于“如何最好地支持 Rust 插件”的问题,而是 Rust 如何制作*.so文件与现有的 C 程序互操作。

下面是一个 C 程序 + C 插件的简化示例:

/* gcc -g -Wall test.c -o test -ldl
   ./test ./test-api.so
 */

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <dlfcn.h>

struct api {
  uint64_t i64;
  int i;
  const char *name;                /* can be NULL */
  void (*load) (void);             /* must not be NULL */
  void (*hello) (const char *str); /* can be NULL …
Run Code Online (Sandbox Code Playgroud)

c rust

5
推荐指数
1
解决办法
1530
查看次数

为什么Box指针传递给C并返回Rust segfault?

一些C代码调用open下面的Rust 调用返回一个指针.后来C代码将完全相同的指针传递回close试图丢弃(释放)它的函数.它是段错误的free(3).为什么?

use std::os::raw::{c_int, c_void};

struct Handle;

extern "C" fn open(_readonly: c_int) -> *mut c_void {
    let h = Handle;
    let h = Box::new(h);
    return Box::into_raw(h) as *mut c_void;
}

extern "C" fn close(h: *mut c_void) {
    let h = unsafe { Box::from_raw(h) };
    // XXX This segfaults - why?
    drop(h);
}
Run Code Online (Sandbox Code Playgroud)

ffi rust

5
推荐指数
2
解决办法
261
查看次数

如何提高boost interval_map查找的性能

我正在使用a boost::icl::interval_map将字节范围映射到一组字符串.地图是从(已排序的)磁盘文件加载,然后我使用下面的代码进行查找.

问题是查找真的很慢.

在我的测试中,我在地图中插入了66425个范围.我分析了代码,基本上> 99.9%的时间花在了各种Boost函数上(没有一个特定的函数很慢,很多时间分布在很多函数上).

可以做些什么来加快速度?

我的树是不平衡的(我如何找到?我怎样才能重新平衡它?)

使用set <string>有问题吗?

计算地图和窗口的交点是一个问题吗?(虽然这是我需要的,所以我看不出怎么做).

using namespace std;
typedef set<string> objects;
typedef boost::icl::interval_map<uint64_t, objects> ranges;
void
find_range (const ranges *map, uint64_t start, uint64_t end,
            void (*f) (uint64_t start, uint64_t end, const char *object,
                       void *opaque),
            void *opaque)
{
  boost::icl::interval<uint64_t>::type window;
  window = boost::icl::interval<uint64_t>::right_open (start, end);

  ranges r = *map & window;

  ranges::iterator iter = r.begin ();
  while (iter != r.end ()) {
    boost::icl::interval<uint64_t>::type range = iter->first;
    uint64_t start = range.lower ();
    uint64_t end = …
Run Code Online (Sandbox Code Playgroud)

c++ boost

3
推荐指数
1
解决办法
1739
查看次数

我怎样才能在*c_char和Vec <u8>之间进行记忆

我有一个Vec<u8>假装是一个大磁盘:

lazy_static! {
    static ref DISK: Mutex<Vec<u8>> = Mutex::new(vec![0; 100 * 1024 * 1024]);
}
Run Code Online (Sandbox Code Playgroud)

我的Rust代码(直接从C调用)有一些函数可以读写这个磁盘,但我不明白我在那些函数中编写的内容是为了在磁盘和C调用者之间进行memcpy(或者是否Vec是最好的结构在这里使用):

extern "C" fn pread(
    _h: *mut c_void,
    buf: *mut c_char,
    _count: uint32_t,
    offset: uint64_t,
    _flags: uint32_t,
) -> c_int {
    // ?
}

extern "C" fn pwrite(
    _h: *mut c_void,
    buf: *const c_char,
    _count: uint32_t,
    offset: uint64_t,
    _flags: uint32_t,
) -> c_int {
    // ?
}
Run Code Online (Sandbox Code Playgroud)

ffi rust

1
推荐指数
1
解决办法
220
查看次数

标签 统计

rust ×3

ffi ×2

boost ×1

c ×1

c++ ×1

gnupg ×1

openpgp ×1