首页 \ 问答 \ asn1 go(客户端证书认证)(asn1 go (client side cert auth))

asn1 go(客户端证书认证)(asn1 go (client side cert auth))

我试图让客户端证书auth工作,并在阅读https://developer.mozilla.org/en-US/docs/Web/HTML/Element/keygen后,我意识到我需要解析一些asn1。

我试图使用的结构是这样的:

type PublicKeyAndChallenge struct {
    Spki asn1.BitString
    Challenge asn1.BitString
}

type SignedPublicKeyAndChallenge struct{
    PublicKeyAndChallenge PublicKeyAndChallenge
    SignitureAlgorithm  asn1.BitString
    Signiture asn1.BitString
}

我将base64编码asn1解码为[]字节,然后我尝试将asn1解组到结构中。

signeeKeySigned := make([]byte, 2048)
    _ , err = base64.StdEncoding.Decode(signeeKeySigned, signeePubKeySigned)
    if ( err != nil ){
        log.Fatal(err)
    }   
    //Parse should be asn.1 encoded
    var signee SignedPublicKeyAndChallenge
    _, err = asn1.Unmarshal(signeeKeySigned, &signee)
    if err != nil {
        log.Fatal(err)
    }  

我收到一个结构错误,所以我相信我的结构一定不是正确的,但我无法弄明白。


I am trying to get client side cert auth working and after reading https://developer.mozilla.org/en-US/docs/Web/HTML/Element/keygen I realised I needed to parse some asn1.

The structure I'm trying to use is this:

type PublicKeyAndChallenge struct {
    Spki asn1.BitString
    Challenge asn1.BitString
}

type SignedPublicKeyAndChallenge struct{
    PublicKeyAndChallenge PublicKeyAndChallenge
    SignitureAlgorithm  asn1.BitString
    Signiture asn1.BitString
}

I decode the base64 encoded asn1 into a []byte, then I try to unmarshal the asn1 into the structure.

signeeKeySigned := make([]byte, 2048)
    _ , err = base64.StdEncoding.Decode(signeeKeySigned, signeePubKeySigned)
    if ( err != nil ){
        log.Fatal(err)
    }   
    //Parse should be asn.1 encoded
    var signee SignedPublicKeyAndChallenge
    _, err = asn1.Unmarshal(signeeKeySigned, &signee)
    if err != nil {
        log.Fatal(err)
    }  

I am getting a structure error so I believe my structure in go must not be correct, but I am not able to figure it out.


原文:https://stackoverflow.com/questions/27992496
更新时间:2024-04-14 20:04

最满意答案

使用bind代码可能有问题,因为它复制对象A2和A1,如果要引用原始对象,可以使用&A2和&A2。 要回答您的问题,您可以使用:

s.registerObserver(EventType::GREEN, std::bind(&A::A_Foo, &A2, std::placeholders::_1));

或者使用lambda,我建议:

s.registerObserver(EventType::GREEN, [&](int i){ A2.A_Foo(i); });

Your code using bind may be problematic since it copies the objects A2 and A1, you can use &A2 and &A2 if you want to reference the original objects. To answer your question, you can use:

s.registerObserver(EventType::GREEN, std::bind(&A::A_Foo, &A2, std::placeholders::_1));

Or use lambda, which I'd recommend:

s.registerObserver(EventType::GREEN, [&](int i){ A2.A_Foo(i); });

相关问答

更多
  • 使用bind代码可能有问题,因为它复制对象A2和A1,如果要引用原始对象,可以使用&A2和&A2。 要回答您的问题,您可以使用: s.registerObserver(EventType::GREEN, std::bind(&A::A_Foo, &A2, std::placeholders::_1)); 或者使用lambda,我建议: s.registerObserver(EventType::GREEN, [&](int i){ A2.A_Foo(i); }); Your code using bin ...
  • 这个怎么样: proxy_macro.hpp #include #include #define PROXY(proxified, member_function, proxy_name) \ class proxy_name ...
  • 我认为问题出在这一行: HEADERS = card.h sortedLinkedList.h deck.h #----------------^ 您已对sortedLinkedList.h指定了依赖sortedLinkedList.h ,但该文件不存在。 您只有一个带有大写SortedLinkedList.h S SortedLinkedList.h 。 规则 %.o: %.cpp $(HEADERS) g++ -c -std=c++11 $< -o $@ 被认为是制作card.o但被拒绝,因 ...
  • 您需要编写语句而不是表达式的原因是您希望利用语句的其他功能,特别是循环的功能。 但是要有用,那就需要声明变量的能力(也被禁止)。 如果将循环功能与可变变量结合使用逻辑分支(如在if语句中),则可以创建无限循环。 不可能确定这样的循环是否会终止( 停止问题 )。 因此一些源将导致编译器挂起。 通过使用递归纯函数,可以引起无限递归,这可以显示出与上述循环能力相当的强大。 但是,C ++在编译时就已经有了这个问题 - 它的模板扩展就出现了,所以编译器已经有了一个“模板堆栈深度”的开关,所以他们知道什么时候放弃。 ...
  • 在C ++中,您最多可以进行一次用户定义的转换。 您不能从ifstream直接构建Algo_t ,但可以使用ifstream构造Matrix_t 。 所以在 Algo_t MyAlgo(ifstream(pMyFileName)); 编译器构造一个临时Matrix_t (您的一个用户定义的转换),然后使用该临时构造MyAlgo In C++ you are allowed up to one user defined conversion. You cannot directly construct a ...
  • 不可以。您可以编写一个接受任何迭代器作为参数但不是函数的函数模板。 如果你有一个类为迭代器类型擦除,那么你可以把它作为参数。 这是一个迭代器类型擦除的文章和代码 。 No. You can write a function template that accepts any iterator as parameter, but not a function. If you had a class that did type erasure for iterators then you could take ...
  • 我很好奇[&idx]做了什么 这是lambda捕获。 它将lambda设置为引用idx 。 它不会用作参数,因为for_each只将一个参数传递给谓词。 如果您改为使用idx作为参数,则不会编译。 从性能角度来看它更好吗? 有可能。 如果你真的想知道,测试每种做法。 I'm curious what exactly does [&idx] do That's the lambda capture. It sets the lambda to take a reference to idx. It won't ...
  • 我也是C风格指针function的粉丝,但重要的是你要认识到void (MyClass::*)(void*)的模拟是function 而不是 function 。 因此,您可以将MapIdToMethod已有的内容复制到: map> bar; 您可以使用与插入MapIdToMethod ( bar.insert(make_pair(2, &MyClass::My ...
  • 你要找的东西不存在。 无论如何,你可以这样做: struct Observer { virtual ~Observer() = 0; virtual void eventA() {} virtual void eventB() {} // ... virtual void eventZ() {} }; Observer::~Observer() { } struct MyObserver: Observer { void eventB() override ...
  • 选项1 使用CRTP惯用法来了解可以存储成员函数的指针类型: template struct Bindable { void bindFunction (int x, void(T::*newFn)()) { mFns.insert(std::make_pair(x,newFn)); } void invokeFunction (int key) { (static_cast(this)->*mFns.at(ke ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)