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
最满意答案
使用
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 ...
-
C ++ 11如何代理只有名称和父类的类函数?(C++11 how to proxy class function having only its name and parent class?)[2022-03-21]
这个怎么样: 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 ++ 11 /生成的构造函数(C++11 / Generated constructor)[2024-04-06]
在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 ... -
C ++ 11迭代器接口(C++11 iterator interface)[2023-05-16]
不可以。您可以编写一个接受任何迭代器作为参数但不是函数的函数模板。 如果你有一个类为迭代器类型擦除,那么你可以把它作为参数。 这是一个迭代器类型擦除的文章和代码 。 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 ... -
for_each函数在c ++ 11中(for_each function in c++11)[2023-07-12]
我很好奇[&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 ++ 11(Map to method c++11)[2024-03-02]
我也是C风格指针function的粉丝,但重要的是你要认识到void (MyClass::*)(void*)的模拟是function而不是 function 。 因此,您可以将MapIdToMethod已有的内容复制到: map > bar; 您可以使用与插入MapIdToMethod ( bar.insert(make_pair(2, &MyClass::My ... -
空覆盖C ++ 11(Empty override C++11)[2022-08-16]
你要找的东西不存在。 无论如何,你可以这样做: 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 ...