出于测试目的,我想打印通过椭圆曲线在Arduino上生成的公钥和私钥。
相关代码如下所示,
var mainArray = [{
key: '2',
value: -20
},
{
key: '3',
value: 0
},
{
key: '1',
value: 10
},
{
key: '5',
value: 10
},
{
key: '7',
value: 10
},
{
key: '4',
value: 40
},
{
key: '6',
value: 40
},
{
key: '8',
value: 40
}
]
var valueArray = [];
//get all the unique value from main array
mainArray.forEach(function(item) {
if (valueArray.indexOf(item.value) === -1) {
valueArray.push(item.value)
}
});
// iterate the value array
valueArray.forEach(function(item) {
// filter will return a new array with objects having value equal to current item
var filteredValue = mainArray.filter(function(x) {
return x.value === item;
});
console.log(filteredValue)
})
但是,它给了我以下错误:
#include <Ed25519.h>
void setup()
{
Serial.begin(9600); // Debugging only
if (!driver.init())
Serial.println("init failed");
uint8_t privateKey[32];
uint8_t publicKey[32];
Ed25519::generatePrivateKey(privateKey);
Ed25519::derivePublicKey(publicKey, privateKey);
Serial.println(publicKey);
Serial.print(",");
Serial.write(privateKey);
}
我也尝试过:
/tmp/arduino_modified_sketch_961866/ask_receiver.pde: In function 'void setup()':
ask_receiver:52: error: call of overloaded 'println(uint8_t [32])' is ambiguous
Serial.println(publicKey);
^
/tmp/arduino_modified_sketch_961866/ask_receiver.pde:5
2:29: note: candidates are:
In file included from /ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Stream.h:26:0,
from /ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/HardwareSerial.h:29,
from /ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Arduino.h:232,
from sketch/ask_receiver.pde.cpp:1:
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:78:12: note: size_t Print::println(const String&) <near match>
size_t println(const String &s);
^
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:78:12: note: no known conversion for argument 1 from 'uint8_t [32] {aka unsigned char [32]}' to 'const String&'
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:79:12: note: size_t Print::println(const char*) <near match>
size_t println(const char[]);
^
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:79:12: note: no known conversion for argument 1 from 'uint8_t [32] {aka unsigned char [32]}' to 'const char*'
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:80:12: note: size_t Print::println(char) <near match>
size_t println(char);
^
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:80:12: note: no known conversion for argument 1 from 'uint8_t [32] {aka unsigned char [32]}' to 'char'
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:81:12: note: size_t Print::println(unsigned char, int) <near match>
size_t println(unsigned char, int = DEC);
^
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:81:12: note: no known conversion for argument 1 from 'uint8_t [32] {aka unsigned char [32]}' to 'unsigned char'
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:82:12: note: size_t Print::println(int, int) <near match>
size_t println(int, int = DEC);
^
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:82:12: note: no known conversion for argument 1 from 'uint8_t [32] {aka unsigned char [32]}' to 'int'
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:83:12: note: size_t Print::println(unsigned int, int) <near match>
size_t println(unsigned int, int = DEC);
^
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:83:12: note: no known conversion for argument 1 from 'uint8_t [32] {aka unsigned char [32]}' to 'unsigned int'
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:84:12: note: size_t Print::println(long int, int) <near match>
size_t println(long, int = DEC);
^
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:84:12: note: no known conversion for argument 1 from 'uint8_t [32] {aka unsigned char [32]}' to 'long int'
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:85:12: note: size_t Print::println(long unsigned int, int) <near match>
size_t println(unsigned long, int = DEC);
^
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:85:12: note: no known conversion for argument 1 from 'uint8_t [32] {aka unsigned char [32]}' to 'long unsigned int'
ask_receiver:54: error: call of overloaded 'write(uint8_t [32])' is ambiguous
Serial.write(privateKey);
^
/tmp/arduino_modified_sketch_961866/ask_receiver.pde:54:28: note: candidates are:
In file included from /ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Arduino.h:232:0,
from sketch/ask_receiver.pde.cpp:1:
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/HardwareSerial.h:129:20: note: virtual size_t HardwareSerial::write(uint8_t) <near match>
virtual size_t write(uint8_t);
^
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/HardwareSerial.h:129:20: note: no known conversion for argument 1 from 'uint8_t [32] {aka unsigned char [32]}' to 'uint8_t {aka unsigned char}'
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/HardwareSerial.h:130:19: note: size_t HardwareSerial::write(long unsigned int) <near match>
inline size_t write(unsigned long n) { return write((uint8_t)n); }
^
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/HardwareSerial.h:130:19: note: no known conversion for argument 1 from 'uint8_t [32] {aka unsigned char [32]}' to 'long unsigned int'
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/HardwareSerial.h:131:19: note: size_t HardwareSerial::write(long int) <near match>
inline size_t write(long n) { return write((uint8_t)n); }
^
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/HardwareSerial.h:131:19: note: no known conversion for argument 1 from 'uint8_t [32] {aka unsigned char [32]}' to 'long int'
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/HardwareSerial.h:132:19: note: size_t HardwareSerial::write(unsigned int) <near match>
inline size_t write(unsigned int n) { return write((uint8_t)n); }
^
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/HardwareSerial.h:132:19: note: no known conversion for argument 1 from 'uint8_t [32] {aka unsigned char [32]}' to 'unsigned int'
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/HardwareSerial.h:133:19: note: size_t HardwareSerial::write(int) <near match>
inline size_t write(int n) { return write((uint8_t)n); }
^
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/HardwareSerial.h:133:19: note: no known conversion for argument 1 from 'uint8_t [32] {aka unsigned char [32]}' to 'int'
In file included from /ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Stream.h:26:0,
from /ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/HardwareSerial.h:29,
from /ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Arduino.h:232,
from sketch/ask_receiver.pde.cpp:1:
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:52:12: note: size_t Print::write(const char*) <near match>
size_t write(const char *str) {
^
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Print.h:52:12: note: no known conversion for argument 1 from 'uint8_t [32] {aka unsigned char [32]}' to 'const char*'
/tmp/arduino_modified_sketch_961866/ask_receiver.pde: In function 'void loop()':
/tmp/arduino_modified_sketch_961866/ask_receiver.pde:80:51: warning: invalid conversion from 'uint8_t* {aka unsigned char*}' to 'const char*' [-fpermissive]
driver.printBuffer("Decrypted:", buf, strlen(buf));
^
In file included from /ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/Arduino.h:25:0,
from sketch/ask_receiver.pde.cpp:1:
/ogobase/home/henk/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/tools/avr/avr/include/string.h:399:15: note: initializing argument 1 of 'size_t strlen(const char*)'
extern size_t strlen(const char *) __ATTR_PURE__;
^
exit status 1
call of overloaded 'println(uint8_t [32])' is ambiguous
但它给我带来了胡言乱语的输出。
我也尝试过:
Serial.write((int)privateKey);
但它给了我以下输出:
String stringOne = String(privateKey, HEX)
Serial.println(stringOne);
最好,我将其输出为十六进制或其他一些我可以通过另一种介质传输的值。
答案 0 :(得分:0)
使用简单的for循环解决它
uint8_t i;
for (i = 0; i < (uint8_t)(sizeof(privateKey)); i++) {
if (privateKey[i] < 0x10) { /* To print "0F", not "F" */
Serial.write('0');
}
Serial.print(privateKey[i], HEX);
}