summaryrefslogtreecommitdiffstats
path: root/rust/src
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2023-03-19 23:08:40 +0100
committerAnton Luka Šijanec <anton@sijanec.eu>2023-03-19 23:08:40 +0100
commitbc79baf384f9055fe7c7ab719cffbd6ce152699b (patch)
treefabcca18f97f21f91c71367c4ff552afc27b3b6c /rust/src
parentfixes on z for radio -- now works (diff)
downloadtravnik-bc79baf384f9055fe7c7ab719cffbd6ce152699b.tar
travnik-bc79baf384f9055fe7c7ab719cffbd6ce152699b.tar.gz
travnik-bc79baf384f9055fe7c7ab719cffbd6ce152699b.tar.bz2
travnik-bc79baf384f9055fe7c7ab719cffbd6ce152699b.tar.lz
travnik-bc79baf384f9055fe7c7ab719cffbd6ce152699b.tar.xz
travnik-bc79baf384f9055fe7c7ab719cffbd6ce152699b.tar.zst
travnik-bc79baf384f9055fe7c7ab719cffbd6ce152699b.zip
Diffstat (limited to 'rust/src')
-rw-r--r--rust/src/main.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/rust/src/main.rs b/rust/src/main.rs
new file mode 100644
index 0000000..64fa16c
--- /dev/null
+++ b/rust/src/main.rs
@@ -0,0 +1,44 @@
+extern crate hex;
+extern crate urlencoding;
+
+use std::collections::HashMap;
+use std::net::IpAddr;
+use chrono::{DateTime, Utc};
+use sha2::{Sha256, Digest};
+use sha1::{Sha1};
+enum Version {
+ V1,
+ V2,
+ Hybrid
+}
+struct Torrent {
+ name: String,
+ sha1: [u8; 20],
+ sha256: [u8; 32],
+ version: Version,
+ files: HashMap<String, u64>,
+ source: IpAddr,
+ date: DateTime<Utc>,
+ hostname: String,
+ software: String
+}
+impl Torrent {
+ fn magnet(&self) -> String {
+ let mut string = String::from("magnet:?dn=");
+ string.push_str(&urlencoding::encode(&self.name));
+ if matches!(self.version, Version::V1) || matches!(self.version, Version::Hybrid) {
+ string.push_str("&xt=urn:btih:");
+ string.push_str(&hex::encode(&self.sha1));
+ }
+ if matches!(self.version, Version::V2) || matches!(self.version, Version::Hybrid) {
+ string.push_str("&xt=urn:btmh:1220");
+ string.push_str(&hex::encode(&self.sha256));
+ }
+ string
+ }
+}
+fn main() {
+ let hash2 = Sha256::new().chain_update(b"test").finalize();
+ let hash1 = Sha1::new().chain_update(b"test").finalize();
+ println!("Hello, world! {:#?} {:#?}", hash2, hash1);
+}