我尝试使用 awk 将时间戳字符串转换为 unix 纪元时间,但多次尝试后失败。
$ echo "2024-04-16 16:32:38.108580" | awk '{ epoch = mktime(gensub(/[:-]/, " ", "g", $1)) + substr($1, index($1, ".")+1) ; print epoch }'
2023
我尝试使用 awk 将时间戳字符串转换为 unix 纪元时间,但多次尝试后失败。
$ echo "2024-04-16 16:32:38.108580" | awk '{ epoch = mktime(gensub(/[:-]/, " ", "g", $1)) + substr($1, index($1, ".")+1) ; print epoch }'
2023
我尝试测试https://www.openssl.org/docs/man1.1.1/man3/EVP_PKEY_CTX_set1_hkdf_salt.html中的示例代码(经过一些修改)。当我运行它时,EVP_PKEY_derive 的函数调用返回 0,但没有明确的错误代码。
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/kdf.h>
int main()
{
char error[1024];
if (EVP_PKEY_CTX* pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, NULL))
{
unsigned char out[1024];
size_t outlen = sizeof(out);
if (EVP_PKEY_derive_init(pctx) <= 0 ||
EVP_PKEY_CTX_set_hkdf_md(pctx, EVP_sha256()) <= 0 ||
EVP_PKEY_CTX_set1_hkdf_salt(pctx, "salt", 4) <= 0 ||
EVP_PKEY_CTX_set1_hkdf_key(pctx, "secret", 6) <= 0 ||
EVP_PKEY_CTX_add1_hkdf_info(pctx, "label", 5) <= 0 )
{
ERR_error_string(ERR_get_error(), error);
printf("%s\n", error);
}
else
{
int r = EVP_PKEY_derive(pctx, NULL, &outlen);
if (r <= 0)
{
ERR_error_string(ERR_get_error(), error);
printf("EVP_PKEY_derive: %d, %s\n", r, error);
}
else
{
printf("%d\n", outlen);
}
}
EVP_PKEY_CTX_free(pctx);
}
return 0;
}
下面是输出。
EVP_PKEY_derive: 0, error:00000000:lib(0):func(0):reason(0)
顺便说一句,我使用的 openssl 是 1.1.1k。
尝试编译以下代码。
#include <string>
#include <boost/any.hpp>
class V
{
public:
V& operator=(int i)
{
v = i;
return *this;
}
V& operator=(const std::string& s)
{
v = s;
return *this;
}
operator int() const
{
return boost::any_cast<int>(v);
}
operator std::string() const
{
return boost::any_cast<std::string>(v);
}
private:
boost::any v;
};
int main()
{
V v;
std::string s1 = "hello", s2;
v = s1;
s2 = v;
}
下面是错误。
$ g++ test__boost_any.cpp
test__boost_any.cpp: In function ‘int main()’:
test__boost_any.cpp:37:9: error: ambiguous overload for ‘operator=’ (operand types are ‘std::__cxx11::string’ {aka ‘std::__cxx11::basic_string<char>’} and ‘V’)
s2 = v;
^
In file included from /usr/include/c++/8/string:52,
from test__boost_any.cpp:1:
/usr/include/c++/8/bits/basic_string.h:668:7: note: candidate: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
operator=(const basic_string& __str)
^~~~~~~~
/usr/include/c++/8/bits/basic_string.h:718:7: note: candidate: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(_CharT) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
operator=(_CharT __c)
^~~~~~~~
/usr/include/c++/8/bits/basic_string.h:736:7: note: candidate: ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
operator=(basic_string&& __str)
^~~~~~~~