Diff
Not logged in

Differences From Artifact [986eee6533]:

To Artifact [a7e38ad771]:


     1      1   // Copyright 2016 MaidSafe.net limited.
     2      2   //
     3      3   // This SAFE Network Software is licensed to you under (1) the MaidSafe.net Commercial License,
     4      4   // version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which
     5      5   // licence you accepted on initial access to the Software (the "Licences").
     6      6   //
     7      7   // By contributing code to the SAFE Network Software, or to this project generally, you agree to be
     8         -// bound by the terms of the MaidSafe Contributor Agreement, version 1.0.  This, along with the
     9         -// Licenses can be found in the root directory of this project at LICENSE, COPYING and CONTRIBUTOR.
            8  +// bound by the terms of the MaidSafe Contributor Agreement.  This, along with the Licenses can be
            9  +// found in the root directory of this project at LICENSE, COPYING and CONTRIBUTOR.
    10     10   //
    11     11   // Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed
    12     12   // under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    13     13   // KIND, either express or implied.
    14     14   //
    15     15   // Please review the Licences for the specific language governing permissions and limitations
    16     16   // relating to use of the SAFE Network Software.
................................................................................
    23     23   use ffi::low_level_api::object_cache::object_cache;
    24     24   use routing::{AppendWrapper, AppendedData, Data, Filter, PrivAppendableData, PrivAppendedData,
    25     25                 PubAppendableData, XOR_NAME_LEN, XorName};
    26     26   use std::{mem, ptr};
    27     27   use std::collections::BTreeSet;
    28     28   use std::iter;
    29     29   
    30         -/// Wrapper for PrivAppendableData and PubAppendableData.
           30  +/// Wrapper for `PrivAppendableData` and `PubAppendableData`.
    31     31   #[derive(Clone, Debug, Hash)]
    32     32   pub enum AppendableData {
    33     33       /// Public appendable data.
    34     34       Pub(PubAppendableData),
    35     35       /// Private appendable data.
    36     36       Priv(PrivAppendableData),
    37     37   }
................................................................................
    60     60   pub enum FilterType {
    61     61       /// BlackList
    62     62       BlackList,
    63     63       /// WhiteList
    64     64       WhiteList,
    65     65   }
    66     66   
    67         -/// Create new PubAppendableData
           67  +/// Create new `PubAppendableData`
    68     68   #[no_mangle]
    69     69   pub unsafe extern "C" fn appendable_data_new_pub(app: *const App,
    70     70                                                    name: *const [u8; XOR_NAME_LEN],
    71     71                                                    o_handle: *mut AppendableDataHandle)
    72     72                                                    -> i32 {
    73     73       helper::catch_unwind_i32(|| {
    74     74           let client = (*app).get_client();
................................................................................
    85     85           owners.insert(owner_key);
    86     86   
    87     87           let mut data = ffi_try!(PubAppendableData::new(name,
    88     88                                                          0,
    89     89                                                          owners,
    90     90                                                          Default::default(),
    91     91                                                          Filter::black_list(iter::empty()))
    92         -            .map_err(CoreError::from));
           92  +                                        .map_err(CoreError::from));
    93     93           let _ = ffi_try!(data.add_signature(&(owner_key, private_signing_key))
    94         -            .map_err(CoreError::from));
           94  +                             .map_err(CoreError::from));
    95     95   
    96     96           let handle = unwrap!(object_cache()).insert_ad(AppendableData::Pub(data));
    97     97   
    98     98           ptr::write(o_handle, handle);
    99     99           0
   100    100       })
   101    101   }
   102    102   
   103         -/// Create new PrivAppendableData
          103  +/// Create new `PrivAppendableData`
   104    104   #[no_mangle]
   105    105   pub unsafe extern "C" fn appendable_data_new_priv(app: *const App,
   106    106                                                     name: *const [u8; XOR_NAME_LEN],
   107    107                                                     o_handle: *mut AppendableDataHandle)
   108    108                                                     -> i32 {
   109    109       helper::catch_unwind_i32(|| {
   110    110           let app = &*app;
................................................................................
   123    123   
   124    124           let mut data = ffi_try!(PrivAppendableData::new(name,
   125    125                                                           0,
   126    126                                                           owners,
   127    127                                                           Default::default(),
   128    128                                                           Filter::black_list(iter::empty()),
   129    129                                                           ffi_try!(app.asym_keys()).0)
   130         -            .map_err(CoreError::from));
          130  +                                        .map_err(CoreError::from));
   131    131           let _ = ffi_try!(data.add_signature(&(owner_key, private_signing_key))
   132         -            .map_err(CoreError::from));
          132  +                             .map_err(CoreError::from));
   133    133   
   134    134           let handle = unwrap!(object_cache()).insert_ad(AppendableData::Priv(data));
   135    135   
   136    136           ptr::write(o_handle, handle);
   137    137           0
   138    138       })
   139    139   }
................................................................................
   158    158           let handle = unwrap!(object_cache()).insert_ad(data);
   159    159   
   160    160           ptr::write(o_handle, handle);
   161    161           0
   162    162       })
   163    163   }
   164    164   
   165         -/// Extract DataIdentifier from AppendableData.
          165  +/// Extract `DataIdentifier` from `AppendableData`.
   166    166   #[no_mangle]
   167    167   pub unsafe extern "C" fn appendable_data_extract_data_id(ad_h: AppendableDataHandle,
   168    168                                                            o_handle: *mut DataIdHandle)
   169    169                                                            -> i32 {
   170    170       helper::catch_unwind_i32(|| {
   171    171           let mut object_cache = unwrap!(object_cache());
   172    172           let data_id = match *ffi_try!(object_cache.get_ad(ad_h)) {
................................................................................
   205    205   
   206    206           let new_ad = {
   207    207               let mut object_cache = unwrap!(object_cache());
   208    208               let ad = ffi_try!(object_cache.get_ad(ad_h));
   209    209   
   210    210               match *ad {
   211    211                   AppendableData::Pub(ref old_data) => {
   212         -                    let mut new_data = ffi_try!(PubAppendableData::new(old_data.name,
   213         -                                                                       old_data.version + 1,
   214         -                                                                       old_data.owners.clone(),
   215         -                                                                       old_data.deleted_data
   216         -                                                                           .clone(),
   217         -                                                                       old_data.filter.clone())
   218         -                        .map_err(CoreError::from));
          212  +                    let mut new_data =
          213  +                        ffi_try!(PubAppendableData::new(old_data.name,
          214  +                                                        old_data.version + 1,
          215  +                                                        old_data.owners.clone(),
          216  +                                                        old_data.deleted_data.clone(),
          217  +                                                        old_data.filter.clone())
          218  +                                         .map_err(CoreError::from));
   219    219                       if include_data {
   220    220                           new_data.data = old_data.data.clone();
   221    221                       }
   222    222                       let owner_key = *ffi_try!(unwrap!(client.lock()).get_public_signing_key());
   223    223                       let private_signing_key =
   224    224                           ffi_try!(unwrap!(client.lock()).get_secret_signing_key()).clone();
   225         -                    let _ = ffi_try!(new_data.add_signature(&(owner_key, private_signing_key))
   226         -                        .map_err(CoreError::from));
          225  +                    let _ = ffi_try!(new_data
          226  +                                         .add_signature(&(owner_key, private_signing_key))
          227  +                                         .map_err(CoreError::from));
   227    228                       AppendableData::Pub(new_data)
   228    229                   }
   229    230                   AppendableData::Priv(ref old_data) => {
   230    231                       let mut new_data =
   231    232                           ffi_try!(PrivAppendableData::new(old_data.name,
   232    233                                                            old_data.version + 1,
   233    234                                                            old_data.owners.clone(),
   234    235                                                            old_data.deleted_data.clone(),
   235    236                                                            old_data.filter.clone(),
   236    237                                                            old_data.encrypt_key.clone())
   237         -                            .map_err(CoreError::from));
          238  +                                         .map_err(CoreError::from));
   238    239                       if include_data {
   239    240                           new_data.data = old_data.data.clone();
   240    241                       }
   241    242                       let owner_key = *ffi_try!(unwrap!(client.lock()).get_public_signing_key());
   242    243                       let private_signing_key =
   243    244                           ffi_try!(unwrap!(client.lock()).get_secret_signing_key()).clone();
   244         -                    let _ = ffi_try!(new_data.add_signature(&(owner_key, private_signing_key))
   245         -                        .map_err(CoreError::from));
          245  +                    let _ = ffi_try!(new_data
          246  +                                         .add_signature(&(owner_key, private_signing_key))
          247  +                                         .map_err(CoreError::from));
   246    248                       AppendableData::Priv(new_data)
   247    249                   }
   248    250               }
   249    251           };
   250    252           let resp_getter = ffi_try!(unwrap!(client.lock()).post(new_ad.clone().into(), None));
   251    253           ffi_try!(resp_getter.get());
   252    254           *ffi_try!(unwrap!(object_cache()).get_ad(ad_h)) = new_ad;
................................................................................
   378    380   #[no_mangle]
   379    381   pub unsafe extern "C" fn appendable_data_encrypt_key(ad_h: AppendableDataHandle,
   380    382                                                        o_handle: *mut EncryptKeyHandle)
   381    383                                                        -> i32 {
   382    384       helper::catch_unwind_i32(|| {
   383    385           let mut object_cache = unwrap!(object_cache());
   384    386           let pk = match *ffi_try!(object_cache.get_ad(ad_h)) {
   385         -            AppendableData::Priv(ref elt) => elt.encrypt_key.clone(),
          387  +            AppendableData::Priv(ref elt) => elt.encrypt_key,
   386    388               _ => ffi_try!(Err(FfiError::UnsupportedOperation)),
   387    389           };
   388    390           let handle = object_cache.insert_encrypt_key(pk);
   389    391           ptr::write(o_handle, handle);
   390    392           0
   391    393       })
   392    394   }
................................................................................
   393    395   
   394    396   /// Get number of appended data items.
   395    397   #[no_mangle]
   396    398   pub unsafe extern "C" fn appendable_data_num_of_data(ad_h: AppendableDataHandle,
   397    399                                                        o_num: *mut usize)
   398    400                                                        -> i32 {
   399    401       helper::catch_unwind_i32(|| {
   400         -        ffi_try!(appendable_data_num_of_data_impl(ad_h, false, o_num));
   401         -        0
   402         -    })
          402  +                                 ffi_try!(appendable_data_num_of_data_impl(ad_h, false, o_num));
          403  +                                 0
          404  +                             })
   403    405   }
   404    406   
   405    407   /// Get number of appended deleted data items.
   406    408   #[no_mangle]
   407    409   pub unsafe extern "C" fn appendable_data_num_of_deleted_data(ad_h: AppendableDataHandle,
   408    410                                                                o_num: *mut usize)
   409    411                                                                -> i32 {
   410    412       helper::catch_unwind_i32(|| {
   411         -        ffi_try!(appendable_data_num_of_data_impl(ad_h, true, o_num));
   412         -        0
   413         -    })
          413  +                                 ffi_try!(appendable_data_num_of_data_impl(ad_h, true, o_num));
          414  +                                 0
          415  +                             })
   414    416   }
   415    417   
   416    418   unsafe fn appendable_data_num_of_data_impl(ad_h: AppendableDataHandle,
   417    419                                              is_deleted_data: bool,
   418    420                                              o_num: *mut usize)
   419    421                                              -> Result<(), FfiError> {
   420    422       let mut object_cache = unwrap!(object_cache());
   421         -    let ad = try!(object_cache.get_ad(ad_h));
          423  +    let ad = object_cache.get_ad(ad_h)?;
   422    424       let num = match *ad {
   423    425           AppendableData::Pub(ref elt) => {
   424    426               if is_deleted_data {
   425    427                   elt.deleted_data.len()
   426    428               } else {
   427    429                   elt.data.len()
   428    430               }
................................................................................
   436    438           }
   437    439       };
   438    440   
   439    441       ptr::write(o_num, num);
   440    442       Ok(())
   441    443   }
   442    444   
   443         -/// Get nth appended DataIdentifier from data.
          445  +/// Get nth appended `DataIdentifier` from data.
   444    446   #[no_mangle]
   445    447   pub unsafe extern "C" fn appendable_data_nth_data_id(app: *const App,
   446    448                                                        ad_h: AppendableDataHandle,
   447    449                                                        n: usize,
   448    450                                                        o_handle: *mut DataIdHandle)
   449    451                                                        -> i32 {
   450    452       helper::catch_unwind_i32(|| {
   451         -        ffi_try!(appendable_data_nth_data_id_impl(app, ad_h, n, false, o_handle));
   452         -        0
   453         -    })
          453  +                                 ffi_try!(appendable_data_nth_data_id_impl(app,
          454  +                                                                           ad_h,
          455  +                                                                           n,
          456  +                                                                           false,
          457  +                                                                           o_handle));
          458  +                                 0
          459  +                             })
   454    460   }
   455    461   
   456         -/// Get nth appended DataIdentifier from deleted data.
          462  +/// Get nth appended `DataIdentifier` from deleted data.
   457    463   #[no_mangle]
   458    464   pub unsafe extern "C" fn appendable_data_nth_deleted_data_id(app: *const App,
   459    465                                                                ad_h: AppendableDataHandle,
   460    466                                                                n: usize,
   461    467                                                                o_handle: *mut DataIdHandle)
   462    468                                                                -> i32 {
   463    469       helper::catch_unwind_i32(|| {
   464         -        ffi_try!(appendable_data_nth_data_id_impl(app, ad_h, n, true, o_handle));
   465         -        0
   466         -    })
          470  +                                 ffi_try!(appendable_data_nth_data_id_impl(app,
          471  +                                                                           ad_h,
          472  +                                                                           n,
          473  +                                                                           true,
          474  +                                                                           o_handle));
          475  +                                 0
          476  +                             })
   467    477   }
   468    478   
   469    479   unsafe fn appendable_data_nth_data_id_impl(app: *const App,
   470    480                                              ad_h: AppendableDataHandle,
   471    481                                              n: usize,
   472    482                                              is_deleted_data: bool,
   473    483                                              o_handle: *mut DataIdHandle)
   474    484                                              -> Result<(), FfiError> {
   475    485       let app = &*app;
   476    486   
   477    487       let mut object_cache = unwrap!(object_cache());
   478    488   
   479         -    let data_id = match *try!(object_cache.get_ad(ad_h)) {
          489  +    let data_id = match *object_cache.get_ad(ad_h)? {
   480    490           AppendableData::Priv(ref elt) => {
   481    491               let priv_data = if is_deleted_data {
   482         -                try!(nth(&elt.deleted_data, n))
          492  +                nth(&elt.deleted_data, n)?
   483    493               } else {
   484         -                try!(nth(&elt.data, n))
          494  +                nth(&elt.data, n)?
   485    495               };
   486         -            let &(ref pk, ref sk) = try!(app.asym_keys());
   487         -            try!(priv_data.open(pk, sk).map_err(CoreError::from)).pointer
          496  +            let &(ref pk, ref sk) = app.asym_keys()?;
          497  +            priv_data
          498  +                .open(pk, sk)
          499  +                .map_err(CoreError::from)?
          500  +                .pointer
   488    501   
   489    502           }
   490    503           AppendableData::Pub(ref elt) => {
   491    504               if is_deleted_data {
   492         -                try!(nth(&elt.deleted_data, n)).pointer
          505  +                nth(&elt.deleted_data, n)?.pointer
   493    506               } else {
   494         -                try!(nth(&elt.data, n)).pointer
          507  +                nth(&elt.data, n)?.pointer
   495    508               }
   496    509           }
   497    510       };
   498    511   
   499    512       let handle = object_cache.insert_data_id(data_id);
   500    513   
   501    514       ptr::write(o_handle, handle);
................................................................................
   506    519   #[no_mangle]
   507    520   pub unsafe extern "C" fn appendable_data_nth_data_sign_key(app: *const App,
   508    521                                                              ad_h: AppendableDataHandle,
   509    522                                                              n: usize,
   510    523                                                              o_handle: *mut SignKeyHandle)
   511    524                                                              -> i32 {
   512    525       helper::catch_unwind_i32(|| {
   513         -        ffi_try!(appendable_data_nth_sign_key_impl(app, ad_h, n, false, o_handle));
   514         -        0
   515         -    })
          526  +                                 ffi_try!(appendable_data_nth_sign_key_impl(app,
          527  +                                                                            ad_h,
          528  +                                                                            n,
          529  +                                                                            false,
          530  +                                                                            o_handle));
          531  +                                 0
          532  +                             })
   516    533   }
   517    534   
   518    535   /// Get nth sign key from deleted data
   519    536   #[no_mangle]
   520    537   pub unsafe extern "C" fn appendable_data_nth_deleted_data_sign_key(app: *const App,
   521    538                                                                      ad_h: AppendableDataHandle,
   522    539                                                                      n: usize,
   523    540                                                                      o_handle: *mut SignKeyHandle)
   524    541                                                                      -> i32 {
   525    542       helper::catch_unwind_i32(|| {
   526         -        ffi_try!(appendable_data_nth_sign_key_impl(app, ad_h, n, true, o_handle));
   527         -        0
   528         -    })
          543  +                                 ffi_try!(appendable_data_nth_sign_key_impl(app,
          544  +                                                                            ad_h,
          545  +                                                                            n,
          546  +                                                                            true,
          547  +                                                                            o_handle));
          548  +                                 0
          549  +                             })
   529    550   }
   530    551   
   531    552   unsafe fn appendable_data_nth_sign_key_impl(app: *const App,
   532    553                                               ad_h: AppendableDataHandle,
   533    554                                               n: usize,
   534    555                                               is_deleted_data: bool,
   535    556                                               o_handle: *mut SignKeyHandle)
   536    557                                               -> Result<(), FfiError> {
   537    558       let app = &*app;
   538    559   
   539    560       let mut object_cache = unwrap!(object_cache());
   540    561   
   541         -    let sign_key = match *try!(object_cache.get_ad(ad_h)) {
          562  +    let sign_key = match *object_cache.get_ad(ad_h)? {
   542    563           AppendableData::Priv(ref elt) => {
   543    564               let priv_data = if is_deleted_data {
   544         -                try!(nth(&elt.deleted_data, n))
          565  +                nth(&elt.deleted_data, n)?
   545    566               } else {
   546         -                try!(nth(&elt.data, n))
          567  +                nth(&elt.data, n)?
   547    568               };
   548         -            let &(ref pk, ref sk) = try!(app.asym_keys());
   549         -            try!(priv_data.open(pk, sk).map_err(CoreError::from)).sign_key
          569  +            let &(ref pk, ref sk) = app.asym_keys()?;
          570  +            priv_data
          571  +                .open(pk, sk)
          572  +                .map_err(CoreError::from)?
          573  +                .sign_key
   550    574   
   551    575           }
   552    576           AppendableData::Pub(ref elt) => {
   553    577               if is_deleted_data {
   554         -                try!(nth(&elt.deleted_data, n)).sign_key
          578  +                nth(&elt.deleted_data, n)?.sign_key
   555    579               } else {
   556         -                try!(nth(&elt.data, n)).sign_key
          580  +                nth(&elt.data, n)?.sign_key
   557    581               }
   558    582           }
   559    583       };
   560    584   
   561    585       let handle = object_cache.insert_sign_key(sign_key);
   562    586   
   563    587       ptr::write(o_handle, handle);
................................................................................
   691    715               let data_id = *ffi_try!(object_cache.get_data_id(data_id_h));
   692    716   
   693    717               let client = unwrap!(client.lock());
   694    718               let sign_pk = ffi_try!(client.get_public_signing_key());
   695    719               let sign_sk = ffi_try!(client.get_secret_signing_key());
   696    720   
   697    721               let appended_data = ffi_try!(AppendedData::new(data_id, *sign_pk, sign_sk)
   698         -                .map_err(CoreError::from));
          722  +                                             .map_err(CoreError::from));
   699    723   
   700    724               match *ffi_try!(object_cache.get_ad(ad_h)) {
   701    725                   AppendableData::Priv(ref elt) => {
   702    726                       let priv_appended_data = ffi_try!(PrivAppendedData::new(&appended_data,
   703    727                                                                               &elt.encrypt_key)
   704         -                        .map_err(CoreError::from));
          728  +                                                              .map_err(CoreError::from));
   705    729                       ffi_try!(AppendWrapper::new_priv(elt.name,
   706    730                                                        priv_appended_data,
   707    731                                                        (sign_pk, sign_sk),
   708    732                                                        elt.version)
   709         -                        .map_err(CoreError::from))
          733  +                                     .map_err(CoreError::from))
   710    734                   }
   711    735                   AppendableData::Pub(ref elt) => {
   712    736                       AppendWrapper::new_pub(elt.name, appended_data, elt.version)
   713    737                   }
   714    738               }
   715    739           };
   716    740   
................................................................................
   717    741           let resp_getter = ffi_try!(unwrap!(client.lock()).append(append_wrapper, None));
   718    742           ffi_try!(resp_getter.get());
   719    743   
   720    744           0
   721    745       })
   722    746   }
   723    747   
   724         -/// Get the current version of AppendableData by its handle
          748  +/// Get the current version of `AppendableData` by its handle
   725    749   #[no_mangle]
   726    750   pub unsafe extern "C" fn appendable_data_version(handle: AppendableDataHandle,
   727    751                                                    o_version: *mut u64)
   728    752                                                    -> i32 {
   729    753       helper::catch_unwind_i32(|| {
   730    754           *o_version = match *ffi_try!(unwrap!(object_cache()).get_ad(handle)) {
   731    755               AppendableData::Pub(ref mut elt) => elt.get_version(),
................................................................................
   732    756               AppendableData::Priv(ref mut elt) => elt.get_version(),
   733    757           };
   734    758   
   735    759           0
   736    760       })
   737    761   }
   738    762   
   739         -/// See if AppendableData size is valid.
          763  +/// See if `AppendableData` size is valid.
   740    764   #[no_mangle]
   741    765   pub unsafe extern "C" fn appendable_data_validate_size(handle: AppendableDataHandle,
   742    766                                                          o_valid: *mut bool)
   743    767                                                          -> i32 {
   744    768       helper::catch_unwind_i32(|| {
   745    769           *o_valid = match *ffi_try!(unwrap!(object_cache()).get_ad(handle)) {
   746    770               AppendableData::Pub(ref elt) => elt.validate_size(),
................................................................................
   747    771               AppendableData::Priv(ref elt) => elt.validate_size(),
   748    772           };
   749    773   
   750    774           0
   751    775       })
   752    776   }
   753    777   
   754         -/// Returns true if the app is one of the owners of the provided AppendableData.
          778  +/// Returns true if the app is one of the owners of the provided `AppendableData`.
   755    779   #[no_mangle]
   756    780   pub unsafe extern "C" fn appendable_data_is_owned(app: *const App,
   757    781                                                     handle: AppendableDataHandle,
   758    782                                                     o_is_owned: *mut bool)
   759    783                                                     -> i32 {
   760    784       helper::catch_unwind_i32(|| {
   761    785           let client = (*app).get_client();
................................................................................
   766    790               AppendableData::Priv(ref mut elt) => elt.get_owners().contains(&my_key),
   767    791           };
   768    792   
   769    793           0
   770    794       })
   771    795   }
   772    796   
   773         -/// Free AppendableData handle
          797  +/// Free `AppendableData` handle
   774    798   #[no_mangle]
   775    799   pub extern "C" fn appendable_data_free(handle: AppendableDataHandle) -> i32 {
   776    800       helper::catch_unwind_i32(|| {
   777         -        let _ = ffi_try!(unwrap!(object_cache()).remove_ad(handle));
   778         -        0
   779         -    })
          801  +                                 let _ = ffi_try!(unwrap!(object_cache()).remove_ad(handle));
          802  +                                 0
          803  +                             })
   780    804   }
   781    805   
   782    806   // Convenience function to access n-th item from the given set, returning FfiError::InvalidIndex
   783    807   // if not found.
   784    808   fn nth<T>(items: &BTreeSet<T>, n: usize) -> Result<&T, FfiError> {
   785    809       items.iter().nth(n).ok_or(FfiError::InvalidIndex)
   786    810   }
   787    811   
   788    812   #[cfg(test)]
   789    813   mod tests {
          814  +    use super::*;
   790    815       use ffi::app::App;
   791    816       use ffi::errors::FfiError;
   792    817       use ffi::low_level_api::{AppendableDataHandle, DataIdHandle};
   793    818       use ffi::low_level_api::misc::*;
   794    819       use ffi::low_level_api::object_cache::object_cache;
   795    820       use ffi::test_utils;
   796    821       use rand;
   797    822       use routing::DataIdentifier;
   798    823       use rust_sodium::crypto::sign;
   799    824       use std::collections::HashSet;
   800         -    use super::*;
   801    825   
   802    826       macro_rules! assert_num_of_data {
   803    827           ($ad_h:ident, $expected:expr) => {
   804    828               let mut num: usize = 0;
   805    829               assert_eq!(appendable_data_num_of_data($ad_h, &mut num), 0);
   806    830               assert_eq!(num, $expected);
   807    831           }
................................................................................
  1156   1180   
  1157   1181           unsafe {
  1158   1182               // Initialise public appendable data
  1159   1183               let mut ad_h = 0;
  1160   1184               assert_eq!(appendable_data_new_pub(&app, &rand::random(), &mut ad_h), 0);
  1161   1185   
  1162   1186               // Public appendable data doens't have a private owner key
         1187  +            let err_code: i32 = FfiError::UnsupportedOperation.into();
  1163   1188               assert_eq!(appendable_data_encrypt_key(ad_h, &mut encrypt_key_h),
  1164         -                       FfiError::UnsupportedOperation.into());
         1189  +                       err_code);
  1165   1190   
  1166   1191               assert_eq!(appendable_data_free(ad_h), 0);
  1167   1192   
  1168   1193               // Initialise private appendable data
  1169   1194               let mut ad_h = 0;
  1170   1195               assert_eq!(appendable_data_new_priv(&app, &rand::random(), &mut ad_h),
  1171   1196                          0);
................................................................................
  1244   1269   
  1245   1270           (id, id_h)
  1246   1271       }
  1247   1272   
  1248   1273       fn get_sign_pk(app: &App) -> sign::PublicKey {
  1249   1274           let client = app.get_client();
  1250   1275           let client = unwrap!(client.lock());
  1251         -        unwrap!(client.get_public_signing_key()).clone()
         1276  +        *unwrap!(client.get_public_signing_key())
  1252   1277       }
  1253   1278   
  1254   1279       fn reload_ad(app: &App, ad_id_h: DataIdHandle, ad_h: &mut AppendableDataHandle) {
  1255   1280           assert_eq!(appendable_data_free(*ad_h), 0);
  1256   1281           unsafe {
  1257   1282               assert_eq!(appendable_data_get(app, ad_id_h, ad_h), 0);
  1258   1283           }
  1259   1284       }
  1260   1285   }