mirror of
https://github.com/mii443/encrypt.git
synced 2025-08-22 15:05:33 +00:00
add compile flag
This commit is contained in:
@ -14,4 +14,7 @@ pub struct Args {
|
||||
|
||||
#[clap(short, long, takes_value = false)]
|
||||
pub debug: bool,
|
||||
|
||||
#[clap(short, long, takes_value = false)]
|
||||
pub compile: bool,
|
||||
}
|
||||
|
@ -1,14 +1,16 @@
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
fs,
|
||||
io::{BufRead, BufReader, Write},
|
||||
fs::{self, File},
|
||||
io::{BufRead, BufReader, Read, Write},
|
||||
net::TcpStream,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
use flate2::{read::ZlibDecoder, write::ZlibEncoder, Compression};
|
||||
|
||||
use crate::{
|
||||
args::Args,
|
||||
config::Config,
|
||||
config::{Config, ConfigFile},
|
||||
elliptic_curve::encryption::Encryption,
|
||||
gpsl::{
|
||||
self,
|
||||
@ -21,8 +23,26 @@ use crate::{
|
||||
};
|
||||
|
||||
pub fn start_client(args: Args) {
|
||||
let mut source =
|
||||
Source::new(fs::read_to_string(&(args.file.unwrap())).expect("Cannot read file."));
|
||||
let file = args.file.clone().unwrap();
|
||||
let file_name = {
|
||||
let file_name = file.file_name();
|
||||
file_name.unwrap().to_string_lossy()
|
||||
};
|
||||
|
||||
let functions = {
|
||||
if file_name.ends_with(".o") {
|
||||
let mut file = fs::File::open(args.file.clone().unwrap()).unwrap();
|
||||
let mut contents = Vec::new();
|
||||
file.read_to_end(&mut contents).unwrap();
|
||||
let mut d = ZlibDecoder::new(&contents[..]);
|
||||
let mut s = String::new();
|
||||
d.read_to_string(&mut s).unwrap();
|
||||
|
||||
serde_json::from_str(&s).unwrap()
|
||||
} else {
|
||||
let mut source = Source::new(
|
||||
fs::read_to_string(&(args.file.clone().unwrap())).expect("Cannot read file."),
|
||||
);
|
||||
|
||||
let mut tokenizer = Tokenizer::new();
|
||||
tokenizer.tokenize(&mut source).unwrap();
|
||||
@ -32,7 +52,20 @@ pub fn start_client(args: Args) {
|
||||
local_vars: HashMap::new(),
|
||||
};
|
||||
|
||||
let functions = parser.functions().unwrap();
|
||||
parser.functions().unwrap()
|
||||
}
|
||||
};
|
||||
|
||||
if args.compile {
|
||||
let functions = serde_json::to_string(&functions).unwrap();
|
||||
|
||||
let mut file = File::create(format!("{}.o", file_name)).unwrap();
|
||||
let mut e = ZlibEncoder::new(Vec::new(), Compression::default());
|
||||
e.write_all(functions.as_bytes()).unwrap();
|
||||
file.write_all(&e.finish().unwrap()).unwrap();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
let mut server_functions: HashMap<String, HashMap<String, Box<Node>>> = HashMap::new();
|
||||
for function in functions.clone() {
|
||||
@ -105,7 +138,6 @@ pub fn start_client(args: Args) {
|
||||
let config = Config::read_or_create();
|
||||
|
||||
let mut gpsl = GPSL::new(
|
||||
source,
|
||||
Some(functions),
|
||||
Some(server_functions),
|
||||
Some(servers),
|
||||
|
@ -6,7 +6,6 @@ use crate::gpsl::external_function::{
|
||||
use crate::gpsl::gpsl_type::GPSLType;
|
||||
use crate::gpsl::node::*;
|
||||
use crate::gpsl::permission::Permission;
|
||||
use crate::gpsl::source::Source;
|
||||
use crate::gpsl::variable::*;
|
||||
use log::*;
|
||||
use primitive_types::U512;
|
||||
@ -34,7 +33,6 @@ pub struct GPSL {
|
||||
pub private_key: Option<U512>,
|
||||
pub public_key: Option<EllipticCurvePoint>,
|
||||
pub global_variables: Vec<Variable>,
|
||||
pub source: Source,
|
||||
pub blocks: VecDeque<Block>,
|
||||
pub external_func: Vec<
|
||||
fn(
|
||||
@ -73,7 +71,6 @@ impl VariableStatus {
|
||||
|
||||
impl GPSL {
|
||||
pub fn new(
|
||||
source: Source,
|
||||
functions: Option<HashMap<String, Box<Node>>>,
|
||||
server_functions: Option<HashMap<String, HashMap<String, Box<Node>>>>,
|
||||
servers: Option<HashMap<String, Arc<Mutex<TcpStream>>>>,
|
||||
@ -91,7 +88,6 @@ impl GPSL {
|
||||
>,
|
||||
) -> GPSL {
|
||||
GPSL {
|
||||
source,
|
||||
functions,
|
||||
server_functions,
|
||||
servers,
|
||||
|
@ -8,7 +8,6 @@ use crate::args::Args;
|
||||
use crate::elliptic_curve::encryption::Encryption;
|
||||
use crate::gpsl::external_function::{ExternalFuncReturn, ExternalFuncStatus, STD_FUNC};
|
||||
use crate::gpsl::node::Node;
|
||||
use crate::gpsl::source::Source;
|
||||
use crate::gpsl::vm::gpsl::{ServerFunctionCall, GPSL};
|
||||
|
||||
fn listen_tcp_server(port: u16) -> TcpStream {
|
||||
@ -41,7 +40,6 @@ pub fn start_server(args: Args) {
|
||||
debug!("Received: {:?}", functions);
|
||||
|
||||
let mut gpsl = GPSL::new(
|
||||
Source::new(String::default()),
|
||||
Some(functions),
|
||||
Some(HashMap::new()),
|
||||
Some(HashMap::new()),
|
||||
|
Reference in New Issue
Block a user