Diff
Not logged in

Differences From Artifact [9d27ed58c2]:

To Artifact [0f48b2cb61]:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
...
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
// Copyright 2016 MaidSafe.net limited.
//
// This SAFE Network Software is licensed to you under (1) the MaidSafe.net
// Commercial License, version 1.0 or later, or (2) The General Public License
// (GPL), version 3, depending on which licence you accepted on initial access
// to the Software (the "Licences").
//
// By contributing code to the SAFE Network Software, or to this project
// generally, you agree to be bound by the terms of the MaidSafe Contributor
// Agreement, version 1.0.
// This, along with the Licenses can be found in the root directory of this
// project at LICENSE, COPYING and CONTRIBUTOR.
//
// 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 errors::CoreError;
use rand::{OsRng, Rng};
use routing::{EntryAction, Value, XorName};
use rust_sodium::crypto::hash::sha256;
use rust_sodium::crypto::secretbox;
use std::collections::{BTreeMap, BTreeSet};
use utils::{symmetric_decrypt, symmetric_encrypt};

/// Information allowing to locate and access mutable data on the network.
#[derive(Clone, Debug, PartialEq, RustcDecodable, RustcEncodable)]
pub struct MDataInfo {
    /// Name of the data where the directory is stored.
    pub name: XorName,
    /// Type tag of the data where the directory is stored.
    pub type_tag: u64,
    /// Key to encrypt/decrypt the directory content.
    /// and the nonce to be used for keys
................................................................................
    }

    Ok(output)
}

fn encrypt_value(info: &MDataInfo, value: &Value) -> Result<Value, CoreError> {
    Ok(Value {
        content: info.enc_entry_value(&value.content)?,
        entry_version: value.entry_version,
    })
}

fn decrypt_value(info: &MDataInfo, value: &Value) -> Result<Value, CoreError> {
    Ok(Value {
        content: info.decrypt(&value.content)?,
        entry_version: value.entry_version,
    })
}

#[cfg(test)]
mod tests {
    use super::*;
    use rand;
    use rust_sodium::crypto::secretbox;


|
|
<
|

|
|
<
<
|

|
|
|
<

|
|










|







 







|
|
|




|
|
|







1
2
3
4

5
6
7
8


9
10
11
12
13

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
...
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
// Copyright 2016 MaidSafe.net limited.
//
// This SAFE Network Software is licensed to you under (1) the MaidSafe.net Commercial License,
// version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which

// licence you accepted on initial access to the Software (the "Licences").
//
// By contributing code to the SAFE Network Software, or to this project generally, you agree to be
// bound by the terms of the MaidSafe Contributor Agreement.  This, along with the Licenses can be


// found in the root directory of this project at LICENSE, COPYING and CONTRIBUTOR.
//
// 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 errors::CoreError;
use rand::{OsRng, Rng};
use routing::{EntryAction, Value, XorName};
use rust_sodium::crypto::hash::sha256;
use rust_sodium::crypto::secretbox;
use std::collections::{BTreeMap, BTreeSet};
use utils::{symmetric_decrypt, symmetric_encrypt};

/// Information allowing to locate and access mutable data on the network.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct MDataInfo {
    /// Name of the data where the directory is stored.
    pub name: XorName,
    /// Type tag of the data where the directory is stored.
    pub type_tag: u64,
    /// Key to encrypt/decrypt the directory content.
    /// and the nonce to be used for keys
................................................................................
    }

    Ok(output)
}

fn encrypt_value(info: &MDataInfo, value: &Value) -> Result<Value, CoreError> {
    Ok(Value {
           content: info.enc_entry_value(&value.content)?,
           entry_version: value.entry_version,
       })
}

fn decrypt_value(info: &MDataInfo, value: &Value) -> Result<Value, CoreError> {
    Ok(Value {
           content: info.decrypt(&value.content)?,
           entry_version: value.entry_version,
       })
}

#[cfg(test)]
mod tests {
    use super::*;
    use rand;
    use rust_sodium::crypto::secretbox;