Skip to content

Commit

Permalink
chore: merging changes made in safe_network fork back into this repo
Browse files Browse the repository at this point in the history
- Make VersionHash independent from the data type such version corresponds to
- Refactor SafeUrl API adding 'from_safekey', 'from_register', 'from_bytes'
- Renaming 'Error::InvalidMediaType' to 'Error::UnsupportedMediaType'
- Replace u64 versions with new 'VersionHash' type
- Use 'tracing' crate instead of 'log'
- Removing 'Sequence' from 'DataType'
- Add a 'Scope' (pub/priv) type for data types
- Renaming 'Blob' data type to 'File'
- Switch from using `anyhow` crate to `color-eyre` in tests

BREAKING CHANGE: the above changes impact the public API.
  • Loading branch information
bochaco committed Jun 14, 2022
1 parent 186109f commit 11d09ba
Show file tree
Hide file tree
Showing 7 changed files with 620 additions and 585 deletions.
18 changes: 9 additions & 9 deletions Cargo.toml
Expand Up @@ -11,16 +11,16 @@ edition = "2018"

[dependencies]
lazy_static = "1.4.0"
log = "~0.4"
multibase = "~0.9"
serde = "1.0.123"
sn_data_types = "~0.19"
thiserror = "1.0.23"
serde = "1.0.137"
sn_interface = "~0.6.1"
thiserror = "1.0.31"
tracing = "~0.1.34"
uhttp_uri = "~0.5"
url = "2.2.0"
urlencoding = "1.1.1"
xor_name = "1"
url = "2.2.2"
urlencoding = "2.1.0"
xor_name = "4.0.1"

[dev-dependencies]
anyhow = "1.0.38"
rand = "~0.7"
color-eyre = "~0.6"
rand = "~0.8.5"
14 changes: 6 additions & 8 deletions examples/safeurls.rs
Expand Up @@ -7,30 +7,28 @@
// specific language governing permissions and limitations relating to use of the SAFE Network
// Software.

use rand::rngs::OsRng;
use sn_data_types::Keypair;
use sn_url::{Error, SafeDataType, SafeUrl, XorUrlBase};
use sn_interface::types::Keypair;
use sn_url::{DataType, Error, SafeUrl, XorUrlBase};
use xor_name::XorName;

fn main() -> Result<(), Error> {
// Let's generate a ranadom key pair
let mut rng = OsRng;
let keypair = Keypair::new_ed25519(&mut rng);
let keypair = Keypair::new_ed25519();

// We get the corresponding Xorname for
// the random public key we obtained
let xorname = XorName::from(keypair.public_key());

// We can encode a SafeKey XOR-URL using the Xorname
// and specifying Base32z as the base encoding for it
let xorurl = SafeUrl::encode_safekey(xorname, XorUrlBase::Base32z)?;
let xorurl = SafeUrl::from_safekey(xorname)?.encode(XorUrlBase::Base32z);

println!("XorUrl: {}", xorurl);

// We can parse a Safe-URL and obtain a SafeUrl instance
// We can parse a Safe-URL string and obtain a SafeUrl instance
let safe_url = SafeUrl::from_url(&xorurl)?;

assert_eq!(safe_url.data_type(), SafeDataType::SafeKey);
assert_eq!(safe_url.data_type(), DataType::SafeKey);
println!("Data type: {}", safe_url.data_type());

assert_eq!(safe_url.xorname(), xorname);
Expand Down
20 changes: 10 additions & 10 deletions src/errors.rs
@@ -1,14 +1,14 @@
// Copyright 2021 MaidSafe.net limited.
// Copyright 2022 MaidSafe.net limited.
//
// This SAFE Network Software is licensed to you under the MIT license <LICENSE-MIT
// http://opensource.org/licenses/MIT> or the Modified BSD license <LICENSE-BSD
// https://opensource.org/licenses/BSD-3-Clause>, at your option. This file may not be copied,
// modified, or distributed except according to those terms. Please review the Licences for the
// specific language governing permissions and limitations relating to use of the SAFE Network
// Software.
// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3.
// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed
// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. Please review the Licences for the specific language governing
// permissions and limitations relating to use of the SAFE Network Software.

use thiserror::Error;

/// Custom Result type for url crate.
pub type Result<T> = std::result::Result<T, Error>;

/// Error type returned by the API
Expand All @@ -21,7 +21,7 @@ pub enum Error {
/// InvalidInput
#[error("InvalidInput: {0}")]
InvalidInput(String),
/// InvalidMediaType
#[error("InvalidMediaType: {0}")]
InvalidMediaType(String),
/// UnsupportedMediaType
#[error("UnsupportedMediaType: {0}")]
UnsupportedMediaType(String),
}

0 comments on commit 11d09ba

Please sign in to comment.