Highly unclear
This commit is contained in:
		
							parent
							
								
									419970d6cd
								
							
						
					
					
						commit
						dc9638998f
					
				
					 2 changed files with 28 additions and 0 deletions
				
			
		
							
								
								
									
										1
									
								
								makefile
									
										
									
									
									
								
							
							
						
						
									
										1
									
								
								makefile
									
										
									
									
									
								
							| 
						 | 
					@ -20,6 +20,7 @@ CFLAGS += -Wno-unused-result
 | 
				
			||||||
CFLAGS += -Wno-unused-local-typedefs
 | 
					CFLAGS += -Wno-unused-local-typedefs
 | 
				
			||||||
CFLAGS += -Wno-unused-const-variable
 | 
					CFLAGS += -Wno-unused-const-variable
 | 
				
			||||||
CFLAGS += -Wno-unused-macros
 | 
					CFLAGS += -Wno-unused-macros
 | 
				
			||||||
 | 
					CFLAGS += -lsodium
 | 
				
			||||||
CFLAGS += -O3
 | 
					CFLAGS += -O3
 | 
				
			||||||
CFLAGS += -g
 | 
					CFLAGS += -g
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										27
									
								
								src/main.cpp
									
										
									
									
									
								
							
							
						
						
									
										27
									
								
								src/main.cpp
									
										
									
									
									
								
							| 
						 | 
					@ -1,8 +1,16 @@
 | 
				
			||||||
#include <iostream>
 | 
					#include <iostream>
 | 
				
			||||||
#include <memory>
 | 
					#include <memory>
 | 
				
			||||||
 | 
					#include <sodium.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "point.hpp"
 | 
					#include "point.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					unsigned char ed25519_pk[crypto_sign_PUBLICKEYBYTES];
 | 
				
			||||||
 | 
					unsigned char ed25519_sk[crypto_sign_SECRETKEYBYTES];
 | 
				
			||||||
 | 
					unsigned char ed25519_seed[crypto_sign_SEEDBYTES];
 | 
				
			||||||
 | 
					unsigned char edwards25519_pk[crypto_scalarmult_ed25519_BYTES];
 | 
				
			||||||
 | 
					unsigned char edwards25519_sk[crypto_scalarmult_ed25519_SCALARBYTES];
 | 
				
			||||||
 | 
					unsigned char h[crypto_hash_sha512_BYTES];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template <typename T> struct Option {
 | 
					template <typename T> struct Option {
 | 
				
			||||||
  private:
 | 
					  private:
 | 
				
			||||||
    T value;
 | 
					    T value;
 | 
				
			||||||
| 
						 | 
					@ -11,6 +19,12 @@ template <typename T> struct Option {
 | 
				
			||||||
  public:
 | 
					  public:
 | 
				
			||||||
    Option() : is_some(false) {}
 | 
					    Option() : is_some(false) {}
 | 
				
			||||||
    Option(T value) : value(value), is_some(true) {}
 | 
					    Option(T value) : value(value), is_some(true) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    T unwrap() {
 | 
				
			||||||
 | 
					        if (!is_some)
 | 
				
			||||||
 | 
					            throw std::runtime_error("Option is empty");
 | 
				
			||||||
 | 
					        return value;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Templated alias for unique_ptr
 | 
					// Templated alias for unique_ptr
 | 
				
			||||||
| 
						 | 
					@ -21,6 +35,16 @@ template <typename T, typename... Args> Box<T> Enbox(Args &&...args) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int main(int argc, char *argv[]) {
 | 
					int main(int argc, char *argv[]) {
 | 
				
			||||||
 | 
					    if (sodium_init() < 0) {
 | 
				
			||||||
 | 
					        return 1;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // create an Ed25519 keypair
 | 
				
			||||||
 | 
					    crypto_sign_keypair(ed25519_pk, ed25519_sk);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Extract the seed from the Ed25519 secret key
 | 
				
			||||||
 | 
					    crypto_sign_ed25519_sk_to_seed(ed25519_seed, ed25519_sk);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Point p = Point(10, 5);
 | 
					    Point p = Point(10, 5);
 | 
				
			||||||
    std::cout << p << std::endl;
 | 
					    std::cout << p << std::endl;
 | 
				
			||||||
    p.move(5, 5);
 | 
					    p.move(5, 5);
 | 
				
			||||||
| 
						 | 
					@ -33,6 +57,9 @@ int main(int argc, char *argv[]) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Box<Point> p_box = std::make_unique<Point>(10, 5);
 | 
					    Box<Point> p_box = std::make_unique<Point>(10, 5);
 | 
				
			||||||
    Box<Point> p_box2 = Enbox<Point>(10, 5);
 | 
					    Box<Point> p_box2 = Enbox<Point>(10, 5);
 | 
				
			||||||
 | 
					    Box<Option<Point>> p_box3 = Enbox<Option<Point>>(Point(10, 5));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    p_box3->unwrap().move(5, 5);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    std::cout << p << std::endl;
 | 
					    std::cout << p << std::endl;
 | 
				
			||||||
    std::cout << *p_box << std::endl;
 | 
					    std::cout << *p_box << std::endl;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue