├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── CONTRIBUTOR ├── COPYING ├── Cargo.toml ├── LICENSE ├── README.md └── src ├── coin ├── mod.rs └── safecoin.rs ├── data ├── immutable_data.rs ├── mod.rs └── structured_data.rs ├── helper.rs ├── id ├── id_type.rs ├── mod.rs ├── public_id_type.rs └── revocation_id_type.rs ├── lib.rs └── test_utils.rs /.gitignore: -------------------------------------------------------------------------------- 1 | *.exe 2 | *.lock 3 | *.swp 4 | tags* 5 | build/ 6 | build-tests/ 7 | target/ 8 | /.idea 9 | /bin 10 | /.project 11 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | os: 2 | - linux 3 | - osx 4 | language: rust 5 | rust: 6 | # - 1.0.0-beta 7 | - nightly 8 | sudo: true 9 | before_install: 10 | - sudo apt-get update -qq 11 | - sudo apt-get install -qq libcurl4-openssl-dev libelf-dev libdw-dev binutils-dev 12 | 13 | env: 14 | global: 15 | secure: "Q8EsABb7DUUkuhefjncpuIKv1P49woHligAlnT2acSj7NZIxKwovgZzKwk13IEHf/CvqWq9lFX8CS6hHE2WJjmgG35EJ8ctFulBo72WRhhDEZy2kdgCnuMoQsjnFE5dT7ZhB/8qP5iZU9p0W0YqcaVwFyEnTeu/9R598klgaXYg=" 16 | 17 | install: 18 | - wget https://github.com/jedisct1/libsodium/releases/download/1.0.0/libsodium-1.0.0.tar.gz 19 | - tar xvfz libsodium-1.0.0.tar.gz 20 | - cd libsodium-1.0.0 && ./configure --prefix=/usr && make && sudo make install && cd .. 21 | script: 22 | - cargo build --verbose 23 | - cargo test --verbose 24 | after_success: | 25 | if [[ $TRAVIS_BRANCH = master ]] && [[ $TRAVIS_PULL_REQUEST = false ]]; then 26 | cargo doc && 27 | echo "" > target/doc/index.html && 28 | sudo pip install ghp-import && 29 | mkdir docs-stage && 30 | COMMIT_MSG=$(git log -1 | tr '[:upper:]' '[:lower:]' | grep "version change to " | tr -d ' ') && 31 | git clone https://github.com/${TRAVIS_REPO_SLUG}.git docs-stage && 32 | cd docs-stage && 33 | git checkout gh-pages; 34 | rm -rf .git*; 35 | # lines 36 - 40 is a patch script for handling old gh-pages structure 36 | OLD_FILE=$(ls | grep "main.js"); 37 | if [[ $OLD_FILE == main* ]]; then 38 | rm -rf * && 39 | echo "" > index.html; 40 | fi 41 | if [[ $COMMIT_MSG == versionchangeto* ]]; then 42 | VERSION=${COMMIT_MSG##*to} && 43 | mkdir -p $VERSION && 44 | mkdir -p latest && 45 | cp -rf ../target/doc/* $VERSION && 46 | cp -rf ../target/doc/* latest && 47 | git config --global user.email dev@miadsafe.net && 48 | git config --global user.name maidsafe-jenkins && 49 | git tag $VERSION -a -m "Version $VERSION" && 50 | git push -q https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG} --tags; 51 | fi 52 | mkdir -p master 53 | cp -rf ../target/doc/* master && 54 | cd .. && 55 | ghp-import -n docs-stage && 56 | git push -fq https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git gh-pages; 57 | wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz && 58 | tar xzf master.tar.gz && 59 | mkdir kcov-master/build && 60 | cd kcov-master/build && 61 | cmake .. && 62 | make && 63 | sudo make install && 64 | cd ../.. && 65 | kcov --coveralls-id=$TRAVIS_JOB_ID --exclude-pattern=/.cargo target/kcov target/debug/maidsafe_types-*; 66 | fi 67 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # MaidSafe Types - Change Log 2 | 3 | ## [0.2.3] 4 | 5 | - Updated dependencies' versions 6 | - Fixed lint warnings caused by latest Rust nightly 7 | 8 | ## [0.2.2] 9 | 10 | - [#81](https://github.com/maidsafe/maidsafe_types/pull/81) Remove payload introduce cbor tagging 11 | 12 | ## [0.2.0] 13 | 14 | - [#78](https://github.com/maidsafe/maidsafe_types/pull/78) make Payload Sendable -- patch 15 | 16 | ## [0.1.52] 17 | - Add account type tags for PayLoad. 18 | 19 | ## [0.1.51] 20 | - Update version in line with routing. 21 | 22 | ## [0.1.5] 23 | - [MAID-1036](https://maidsafe.atlassian.net/browse/MAID-1036) Add SafeCoin type with entries i) type tag ii) name iii) owners iv) previous owners, and v) signatures. Implement and test Sendable, Encodable, Decodable, PartialEq and fmt::Debug traits for SafeCoin type. Merges [MAID-1044](https://maidsafe.atlassian.net/browse/MAID-1044) to a single unit of work. 24 | - [MAID-1119](https://maidsafe.atlassian.net/browse/MAID-1036) Implement TypeTag for StructuredData type. 25 | - [MAID-1056](https://maidsafe.atlassian.net/browse/MAID-1056) Write tests to confirm invariants of all types 26 | 27 | ## [0.1.4] 28 | - Remove anonymous public types 29 | - [MAID-1053](https://maidsafe.atlassian.net/browse/MAID-1053) Anonymous public types to be included as part of the body of the public type 30 | - [MAID-1058](https://maidsafe.atlassian.net/browse/MAID-1058) Change tests to reflect the above task 31 | - Modifications to Id types 32 | - [MAID-1029](https://maidsafe.atlassian.net/browse/MAID-1029) Remove name from types to enhance type invariance 33 | - [MAID-1035](https://maidsafe.atlassian.net/browse/MAID-1035) Add a member of signature type to Id types. The signature in pure keys is sign_using_own_private_key(public keys + type tag). And in dependent keys, is sign_using_owner_private_key(public keys + owner public key + type tag) 34 | - [MAID-1041](https://maidsafe.atlassian.net/browse/MAID-1041) Remove maid_signature and mpid_signature from PublicMaid and PublicAnMaid 35 | - [MAID-1115](https://maidsafe.atlassian.net/browse/MAID-1115) Update StructuredData 36 | - [MAID-1116](https://maidsafe.atlassian.net/browse/MAID-1116) Create 2 new ImmutableData types 37 | 38 | ## [0.0.0 - 0.1.3] 39 | - Add all DataTypes for Data Put/Get 40 | - Add Encode/Decode traits for all types (cbor) 41 | - API version 0.0.8 42 | - Write tests to confirm serialising and parsing of all types 43 | -------------------------------------------------------------------------------- /CONTRIBUTOR: -------------------------------------------------------------------------------- 1 | MaidSafe Contributor Agreement version 1.0 1. Scope of this Agreement This MaidSafe Contributor Agreement ("MCA") applies to any contribution (as defined below) that you make to any software or other product or project managed by us (the "project"), and sets out the intellectual property rights you assign and grant to us in the contributed materials. The term "us" shall mean MaidSafe.net Limited. The term "you" shall mean the person or entity identified below. 2. Acceptance You should read this agreement carefully before posting any contributions (as defined below) to the project. Your posting of any contribution to this project will be deemed to constitute acceptance of the terms of this MCA. This MCA is a binding legal agreement between you and us. 3. Intellectual property rights The term "contributions" or "contributed materials" means any source code, object code, patch, tool, sample, graphic, specification, manual, documentation, or any other material posted or submitted by you to the project. The term "intellectual property rights" means any patents, rights to inventions, copyrights and similar rights, rights in know-how and all other intellectual property rights anywhere in the world for the full term of those rights including all registrations and applications and the right to apply for registrations. In relation to intellectual property rights in your contributions: * you hereby assign to us with full title guarantee all the intellectual property rights (existing and future) in your contributions (the "rights"), and we hereby grant to you a perpetual, irrevocable, non-exclusive, worldwide, no-charge, royalty-free, unrestricted license to use the rights for any purpose. To the extent that such assignment is or becomes invalid, ineffective or unenforceable, you hereby grant to us a perpetual, irrevocable, non-exclusive, worldwide, no-charge, royalty-free, unrestricted license to use the rights for any purpose (including, at our option, the right to sublicense these same rights to third parties through multiple levels of sublicensees or other licensing arrangements. * you hereby irrevocably and unconditionally waive all moral rights which you may have in your contributions in whatever part of the world such rights may be enforceable; * you agree to, without charge, execute and do all such acts, documents, matters and things as may be necessary or reasonably required to obtain patent, copyright or other protection for any of your contributions (or software in which they are included) or improvements or developments to them and to vest title to the intellectual property rights in them in us and you irrevocably appoint us to be your attorney and in your name and on your behalf to execute and do any such acts described above for the same purpose if needed; and * you agree that neither of us has any duty to consult with, obtain the consent of, pay or render an accounting to the other for any use or distribution of your contribution. This MCA is effective on the date you first submitted a contribution to us. Any contribution we make available under any license will also be made available under a suitable FSF (Free Software Foundation) or OSI (Open Source Initiative) approved license. You covenant, represent, warrant and agree that: * each contribution that you submit (1) is and shall be an original work of authorship and you can legally assign and grant the rights set out in this MCA, and (2) does not include any third party code or other materials; * no contribution will violate any third party's intellectual property rights; and * each contribution shall be in compliance with (and will not need a licence or permission under) applicable export or import laws. You agree to notify us if you become aware of any circumstance which would make any of the foregoing representations inaccurate in any respect. MaidSafe may publicly disclose your participation in the project, including the fact that you have signed the MCA. Any notice or other written communication to be given under or in connection with this agreement shall be in writing, no term shall be varied by statement, conduct or act of any party except that the parties may amend this agreement only by letter or written instrument signed by both parties. This agreement sets out the entire agreement and understanding between the parties relating to your contributions. This MCA is governed by Scottish law and subject to the jurisdiction of the Scottish courts save that we or you may bring action in other courts to the extent necessary to protect or enforce our intellectual property rights. -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "maidsafe_types" 3 | version = "0.2.3" 4 | authors = ["MaidSafe Developers "] 5 | description = "Types for maidsafe clients and vaults." 6 | documentation = "http://maidsafe.net/maidsafe_types/latest" 7 | repository = "https://github.com/maidsafe/maidsafe_types" 8 | readme = "README.md" 9 | license = "GPL-3.0" 10 | homepage = "http://maidsafe.net" 11 | 12 | [dependencies] 13 | rustc-serialize = "*" 14 | cbor = "*" 15 | sodiumoxide = "*" 16 | rand = "*" 17 | routing = "0.2.*" 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MaidSafe.net Commercial Licence 1.0 2 | 3 | DATE [insert date] 4 | 5 | 6 | PARTIES 7 | 8 | (1) MaidSafe.next Ltd registered company number SC297540 of 72 Templehill, Troon, Scotland, 9 | KA10 6BE; and 10 | 11 | (2) [INSERT FULL COMPANY NAME OF CUSTOMER] (registered company number [number]) of [address] 12 | (the "Customer"). 13 | 14 | 15 | INTRODUCTION 16 | 17 | MaidSafe has agreed to supply and license, and the Customer has agreed to use and pay for, 18 | MaidSafe's proprietary software on the terms set out in this agreement. 19 | 20 | 21 | 1. Definitions 22 | 23 | In this agreement: 24 | 25 | "Affiliate" means in relation to any company, any body corporate which is from time to time a 26 | holding company of that company, a subsidiary of that company or a subsidiary of a holding 27 | company of that company ("holding company" and "subsidiary" having the meanings attributed to 28 | them by s.1159 Companies Act 2006); 29 | 30 | "Intellectual Property Rights" means any patents, rights to inventions, copyrights and similar 31 | rights, rights in know-how and all other intellectual property rights anywhere in the world 32 | for the full term of those rights including all registrations and applications and the right 33 | to apply for registrations; 34 | 35 | "Licence" shall mean the licence in clause 3 of this agreement; 36 | 37 | "Object" form shall mean any form resulting from mechanical transformation or translation of a 38 | Source form, including but not limited to compiled object code, generated documentation, and 39 | conversions to other media types; 40 | 41 | "Software" means the source or binary form of any MaidSafe.net limited developed code; and 42 | 43 | "Source" form shall mean software source code. 44 | 45 | 46 | 2. Supply of the Software 47 | 48 | MaidSafe will make available to the Customer the Software for download. 49 | 50 | 51 | 3. Licence 52 | 53 | 3.1 In consideration of, and subject to payment of, the charges payable under this agreement, 54 | MaidSafe grants the Customer a perpetual non-exclusive licence to use reproduce, sublicense, 55 | and distribute the Software in Source or Object form, in each case in accordance with this 56 | clause 3, for the duration of this agreement. This right includes the right to use the 57 | Intellectual Property Rights in the Software, including patent rights, and the Customer 58 | acknowledges that its use of the Software or any similar software (or any modified version of 59 | the Software or any software that is based on or includes any part of the Software) other than 60 | in accordance with the terms of this agreement (including the payment of the charges when due) 61 | would infringe MaidSafe's Intellectual Property Rights, including patents rights, and in such 62 | cases MaidSafe may terminate this Agreement without prejudice to its rights to claim damages, 63 | account of profits and/or injunctive relief. 64 | 65 | 3.2 Customer may reproduce and distribute copies of the Software in any medium, with or without 66 | modifications, and in Source or Object form, provided that Customer meets the following 67 | conditions: 68 | 69 | (a) Customer must ensure that any permitted user is required to enter into a written 70 | software licence and is not allowed to use the Software (including any modified version 71 | of the Software or any software that is based on or includes any part of the Software) 72 | in any manner that would not be permitted by this Licence; 73 | 74 | (b) Customer must cause any modified files to carry prominent notices stating that Customer 75 | changed the files; 76 | 77 | (c) Customer must retain, in the Source form of any copies of the Software (including any 78 | modified version of the Software or any software that is based on or includes any part 79 | of the Software) or any part thereof that Customer distributes, all copyright, patent, 80 | trademark, and attribution notices from the Source form of the Software; and 81 | 82 | (d) if the Software includes a "NOTICE" text file as part of its distribution, then any 83 | copies of the Software (including any modified version of the Software or any software 84 | that is based on or includes any part of the Software) or any part that Customer 85 | distributes must include a readable copy of the attribution notices contained within 86 | such NOTICE file in at least one of the following places: 87 | 88 | (i) within a NOTICE text file distributed as part of the Software; 89 | 90 | (ii) within the Source form or documentation, if provided along with the Software; or 91 | 92 | (iii) within a display generated by the Software, if and wherever such third-party 93 | notices normally appear. The contents of the NOTICE file are for informational 94 | purposes only and do not modify the Licence. 95 | 96 | 3.3 Except as expressly permitted otherwise by any term of this agreement, only the Customer is 97 | permitted to use the Software. Use by the Customer includes use by the Customer's employees 98 | and contractors provided that such use is solely on behalf of the Customer and for the 99 | purposes of the Customer's business. 100 | 101 | 3.4 The Customer may make such backup copies of the Software as are reasonably necessary to 102 | support the Customer's use of the Software in accordance with this agreement. MaidSafe will 103 | own the Intellectual Property Rights in any such backup copies. 104 | 105 | 3.5 The Customer may reverse engineer or decompile the Software but only to the extent allowed 106 | under applicable law and on the basis that Customer will request interoperability information 107 | from MaidSafe. 108 | 109 | 3.6 The Customer will comply with any reasonable instructions which MaidSafe gives the Customer 110 | relating to the use of the Software (or any modified version of the Software or any software 111 | that is based on or includes any part of the Software). The Customer will allow MaidSafe 112 | access to any premises controlled by the Customer in order to allow MaidSafe to check that the 113 | Software (or any modified version of the Software or any software that is based on or includes 114 | any part of the Software) is being used only as permitted. 115 | 116 | 3.7 This agreement does not grant permission to use the trade names, trademarks, service marks, or 117 | product names of the Licensor, except as required for reasonable and customary use in 118 | describing the origin of the Software and complying with this agreement. 119 | 120 | 121 | 4. Limited warranty 122 | 123 | 4.1 MaidSafe warrants that it will perform its obligations under this agreement with reasonable 124 | care and skill. 125 | 126 | 4.2 If the warranty in clause 4.1 is breached, the Customer must tell MaidSafe as soon as 127 | possible. The Customer must give MaidSafe a reasonable time to fix the problem or to 128 | re-perform any relevant services. This will be done without any additional charge to the 129 | Customer. If MaidSafe is able to do this within a reasonable time, MaidSafe will have no 130 | other obligations or liability in relation to that breach. If MaidSafe is unable to do this 131 | within a reasonable time or MaidSafe does not think that it is a sensible way to deal with the 132 | problem, then MaidSafe may if it wishes elect to take back the Software and to refund to the 133 | Customer all of the money which the Customer has paid to MaidSafe under this agreement. Where 134 | the problem relates to a portion of the Software and other elements supplied which are capable 135 | of use separately without material detriment to the Customer, MaidSafe may take back (and 136 | refund in respect of) affected portions only. 137 | 138 | 4.3 Apart from the terms set out in this agreement, no conditions, warranties or other terms apply 139 | to the Software or its supply or Licence under this agreement. In particular, no implied 140 | conditions, warranties or other terms relating to satisfactory quality or fitness for any 141 | purpose will apply to anything supplied under this agreement. MaidSafe does not warrant or 142 | enter into any terms to the effect that the Software: 143 | 144 | (a) will perform any particular function or purpose; or 145 | 146 | (b) be entirely free from defects or that its operation will be entirely error free. 147 | 148 | 4.4 MaidSafe will not be liable for breach of any of the warranties or any other terms in this 149 | agreement to the extent that the breach arises from: 150 | 151 | (a) use of the Software other than in accordance with normal operating procedures or as 152 | otherwise notified to the Customer by MaidSafe; 153 | 154 | (b) any alterations to the Software made by anyone other than MaidSafe or someone authorised 155 | by MaidSafe; 156 | 157 | (c) any problem with the computer on which the Software is installed, any equipment 158 | connected to that computer or any other software which is installed on that computer; 159 | 160 | (d) any abnormal or incorrect operating conditions; or 161 | 162 | (e) use of the Software in combination with any other hardware or software, unless this use 163 | has been approved by MaidSafe in writing. 164 | 165 | 166 | 5. Limitation of Liability 167 | 168 | 5.1 Neither party's liability: 169 | 170 | (a) for death or personal injury caused by its negligence or the negligence of its employees 171 | or agents; 172 | 173 | (b) for breach of clause 7 (Confidentiality); or 174 | 175 | (c) for fraudulent misrepresentation, is excluded or limited by this agreement, even if any 176 | other term of this agreement would otherwise suggest that this might be the case. 177 | 178 | 5.2 Other than as set out in clause 5.1, neither party shall be liable to the other (whether for 179 | breach of contract, negligence or for any other reason) for any: 180 | 181 | (a) loss of profits; 182 | 183 | (b) loss of sales; 184 | 185 | (c) loss of revenue; 186 | 187 | (d) loss of any software or data; 188 | 189 | (e) loss of use of hardware, software or data; 190 | 191 | (f) indirect, consequential or special loss. 192 | 193 | 5.3 Subject to clauses 5.1 and 5.2, MaidSafe's total aggregate liability under this agreement and 194 | in relation to anything which MaidSafe has done or not done in connection with this agreement 195 | (and whether the liability arises because of breach of contract, negligence or for any other 196 | reason) shall be limited to: 197 | 198 | (a) an amount equal to 125% of the total amount payable by the Customer under this agreement 199 | in the preceding 12 months; or 200 | 201 | (b) if the amount referred to in (a) cannot be calculated accurately at the time the 202 | relevant liability is to be assessed, or if it is less than £5,000, to £5,000 203 | 204 | 205 | 6. Charges 206 | 207 | 6.1 Schedule 1 sets out the licence fees and other charges payable by the Customer under this 208 | agreement. The charges are due on the dates (or on the happening of the events) specified in 209 | schedule 1. 210 | 211 | 6.2 MaidSafe may invoice the Customer for the charges as soon as they become due. The Customer 212 | must pay the invoices within 30 days of receiving them (and if MaidSafe posts them to the 213 | Customer, the Customer will be treated as having received them two working days later unless 214 | the Customer can show that this was not the case). 215 | 216 | 6.3 Where any charges are based on the Customer's revenues the Customer shall keep all accounts 217 | and documents necessary to evidence such revenues and to support any calculation of the 218 | relevant revenue share, and shall provide copies to MaidSafe on request. Customer shall allow 219 | MaidSafe and its agents to enter into Customer's premises and to have access to all such 220 | accounts and documents upon reasonable request. Where Customer's accounts and documents 221 | illustrate that Customer has underpaid any charges (or MaidSafe can otherwise demonstrate 222 | this) Customer shall immediately pay the balance due to MaidSafe plus MaidSafe's reasonable 223 | costs of audit. This clause 6.3 shall survive termination or expiry of this agreement for 6 224 | years. 225 | 226 | 6.4 MaidSafe may charge interest on all sums outstanding beyond the date on which they are due for 227 | payment under this agreement. Interest may be charged on that basis from the date payment was 228 | due until the date of payment (including after any judgement has been obtained) at the rate of 229 | 3% per calendar month or part thereof. 230 | 231 | 6.5 The amounts specified in schedule 1 do not include VAT or any other taxes on supplies and the 232 | Customer will pay these to MaidSafe as well as the amounts concerned. 233 | 234 | 235 | 7. Confidentiality 236 | 237 | 7.1 Each party will keep confidential any information which the other supplies to it in connection 238 | with this agreement. Confidential information will include the Software and any related 239 | documentation; all information marked as being confidential; and any other information which 240 | might reasonably be assumed to be confidential. The obligations as to confidentiality in this 241 | agreement will not apply to any information which: 242 | 243 | (a) is available to the public other than because of any breach of this agreement; 244 | 245 | (b) is, when it is supplied, already known to whomever it is disclosed to in circumstances 246 | in which they are not prevented from disclosing it to others; 247 | 248 | (c) is independently obtained by whomever it is disclosed to in circumstances in which they 249 | are not prevented from disclosing it to others; or 250 | 251 | (d) is required to be disclosed by law or by any court or tribunal with proper authority to 252 | order its disclosure (but only to the extent of such requirements). 253 | 254 | 255 | 8. Term and termination 256 | 257 | 8.1 This agreement will commence on the date set out on page 1 and will continue indefinitely 258 | until terminated in accordance with this clause 8. 259 | 260 | 8.2 Either party may terminate this agreement if: 261 | 262 | (a) the other materially breaches any term of this agreement and it is not possible to 263 | remedy that breach or it is possible to remedy that breach, but the other fails to do so 264 | within 30 days of being asked to do so; or 265 | 266 | (b) the other suffers any of the following event: 267 | 268 | (i) a meeting of creditors of that party being held or an arrangement or composition 269 | with or for the benefit of its creditors (including a voluntary arrangement as 270 | defined in the Insolvency Act 1986) being proposed by or in relation to that 271 | party; 272 | 273 | (ii) a chargeholder, receiver, administrative receiver or other similar party taking 274 | possession of or being appointed over or any distress, execution or other process 275 | being levied or enforced (and not being discharged within seven days) on the whole 276 | or a material part of the assets of that party; 277 | 278 | (iii) that party ceasing to carry on business or being deemed to be unable to pay its 279 | debts within the meaning of section 123 Insolvency Act 1986; 280 | 281 | (iv) that party or its directors or the holder of a qualifying floating charge or any 282 | of its creditors giving notice of their intention to appoint, appointing or making 283 | an application to the court for the appointment of, an administrator; 284 | 285 | (v) a petition being advertised or a resolution being passed or an order being made 286 | for the administration or the winding-up, bankruptcy or dissolution of that party; 287 | and/or 288 | 289 | (vi) the happening in relation to that party of an event analogous to any of the above 290 | in any jurisdiction in which it is incorporated or resident or in which it carries 291 | on business or has assets. 292 | 293 | 8.3 MaidSafe may terminate this agreement if: 294 | 295 | (a) Customer fails to pay any charges within 60 days of their due date; or 296 | 297 | (b) should the Software become, or in MaidSafe's reasonable opinion is likely to become, the 298 | subject of a claim of intellectual property infringement claim. 299 | 300 | 8.4 Apart from any other rights which MaidSafe might have, if the Customer breaches this agreement 301 | MaidSafe may suspend performance of any of its obligations or any of the Customer's rights 302 | under this agreement until the Customer remedies the breach to the reasonable satisfaction of 303 | MaidSafe. 304 | 305 | 306 | 9. Consequences of termination 307 | 308 | 9.1 If this agreement is terminated (regardless of who terminates it and regardless of the reason) 309 | the Customer will immediately on termination: 310 | 311 | (a) cease using the Software (including any modified version of the Software or any software 312 | that is based on or includes any part of the Software); 313 | 314 | (b) return all copies of the Software to MaidSafe or (if the copies are on media which is 315 | non-removable and forms part of equipment belonging to the Customer) delete all copies 316 | in such a way that they cannot be recovered; and 317 | 318 | (c) confirm to MaidSafe in writing that both of the above things have been done. 319 | 320 | 9.2 Termination of this agreement will not affect any accrued rights or liabilities which either 321 | MaidSafe or the Customer may have by the time termination takes effect. Clauses 5, 6 (for 322 | unpaid charges), 7 and 9 shall survive termination or expiry of this agreement and any other 323 | clause shall survive termination or expiry if expressly stated. 324 | 325 | 326 | 10. Other terms 327 | 328 | 10.1 The Customer may not assign any of the Customer's rights or obligations under this agreement. 329 | MaidSafe may assign this agreement or any of MaidSafe's rights or obligations under this 330 | agreement to someone else, provided MaidSafe tells the Customer in writing if it does so. 331 | 332 | 10.2 Neither party has any authority to enter into a contract for or on behalf of the other party, 333 | to assume a liability on behalf of the other party or to pledge the credit of the other party, 334 | unless such authority is expressly granted in writing by the other party. Neither party may 335 | act as if it has such authority and must not represent (expressly or by implying it) that it 336 | has such authority. 337 | 338 | 10.3 MaidSafe will not be liable to the Customer for any breach of this agreement which arises 339 | because of any circumstances which MaidSafe cannot reasonably be expected to control. 340 | 341 | 10.4 All notices and consents relating to this agreement must be in writing. All variations to 342 | this agreement must be agreed, set out in writing and signed on behalf of both MaidSafe and 343 | the Customer before they take effect. 344 | 345 | 10.5 In this agreement, unless it says otherwise: 346 | 347 | (a) reference to a person includes a legal person (such as a limited company) as well as a 348 | natural person; 349 | 350 | (b) reference to this agreement includes reference to the schedules and appendices and other 351 | documents attached to it or incorporated by reference into it (all as amended or added 352 | to from time to time); 353 | 354 | (c) reference to "including" in this agreement shall be treated as being by way of example 355 | and shall not limit the general applicability of any preceding words; 356 | 357 | (d) reference to any legislation shall be to that legislation as amended, extended or 358 | re-enacted from time to time and to any subordinate provision made under that 359 | legislation; 360 | 361 | (e) references to clauses or schedules shall be to those in this agreement; 362 | 363 | (f) reference to this agreement shall include reference to it after it has been amended, 364 | added to or replaced by a new agreement. 365 | 366 | 10.6 Except to the extent that this agreement expressly says otherwise, nothing in this agreement 367 | shall create a partnership between the parties or give the rights of a partner to either 368 | party. 369 | 370 | 10.7 Any software supplied or Licenced under this agreement will not be treated as goods within the 371 | meaning of the Sale of Goods Act 1979. Firmware will be treated as part of the goods in which 372 | it is installed. 373 | 374 | 10.8 This agreement sets out all of the terms that have been agreed between MaidSafe and the 375 | Customer in relation to the subjects covered by it. Subject to clause 5.1, no other 376 | representations or terms shall apply or form part of this agreement. The Customer 377 | acknowledges that it has not been influenced to enter this agreement by anything MaidSafe has 378 | said or done or committed to do, except as expressly recorded herein. 379 | 380 | 10.9 No term of this agreement is enforceable under the Contracts (Rights of Third Parties) Act 381 | 1999 by a person who is not a party to this agreement. 382 | 383 | 10.10 This agreement is governed by Scottish law. Both MaidSafe and the Customer submit to the 384 | exclusive jurisdiction of the Scottish courts in relation to any dispute concerning this 385 | agreement but MaidSafe is also entitled to apply to any court worldwide for injunctive and 386 | other remedies in order to protect or enforce its Intellectual Property Rights. 387 | 388 | 389 | SCHEDULE 1 390 | 391 | CHARGES 392 | 393 | 394 | 1. Customer shall pay to MaidSafe 1% of Qualifying Revenue. 395 | 396 | 2 "Qualifying Revenue" shall mean any revenue generated directly or indirectly by Customer or 397 | any Affiliate of Customer through: 398 | 399 | (a) use of the Software (including any modified version of the Software or any software that 400 | is based on or includes any part of the Software); or 401 | 402 | (b) the provision of services directly or indirectly to any person using the Software 403 | (including any modified version of the Software or any software that is based on or 404 | includes any part of the Software), 405 | 406 | ("Qualifying Activities") less any VAT charged on such Qualifying Activities. 407 | 408 | 3. Where any Qualifying Activity is discounted or provided for free (whether through bundling or 409 | otherwise) it will be deemed to be provided at market rate and the relevant Qualifying Revenue 410 | shall be calculated accordingly. 411 | 412 | 4. The charges will be payable quarterly in arrears. 413 | 414 | 5. Within 5 days of the end of each month Customer will provide to MaidSafe a statement setting 415 | out the Qualifying Revenue for the month. MaidSafe shall invoice Customer within 5 days of 416 | the end of each third month. Where no statement is provided or MaidSafe has cause to believe 417 | it to be inaccurate it may invoke its audit rights under this agreement. 418 | 419 | 420 | SIGNED on behalf of both parties on the date set out on page 1 of this agreement: 421 | 422 | 423 | 424 | SIGNED: ..................................................................... 425 | for and on behalf of MaidSafe 426 | 427 | 428 | 429 | ..................................................................... 430 | Name/status 431 | 432 | 433 | 434 | 435 | SIGNED: ..................................................................... 436 | for and on behalf of the Customer 437 | 438 | 439 | 440 | ..................................................................... 441 | Name/status 442 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ***This repository is no longer maintained*** 2 | # It has been moved to the maidsafe-archive organisation for reference only 3 | # 4 | # 5 | # 6 | # 7 | # maidsafe_types 8 | 9 | [![](https://img.shields.io/badge/Project%20SAFE-Approved-green.svg)](http://maidsafe.net/applications) [![](https://img.shields.io/badge/License-GPL3-green.svg)](https://github.com/maidsafe/maidsafe_types/blob/master/COPYING) 10 | 11 | **Primary Maintainer:** Brian Smith (brian.smith@maidsafe.net) 12 | 13 | |Crate|Linux|Windows|OSX|Coverage|Issues| 14 | |:------:|:-------:|:-------:|:-------:|:-------:|:-------:| 15 | |[![](http://meritbadge.herokuapp.com/maidsafe_types)](https://crates.io/crates/maidsafe_types)|[![Build Status](https://travis-ci.org/maidsafe/maidsafe_types.svg?branch=master)](https://travis-ci.org/maidsafe/maidsafe_types)|[![Build Status](http://ci.maidsafe.net:8080/buildStatus/icon?job=maidsafe_types_win64_status_badge)](http://ci.maidsafe.net:8080/job/maidsafe_types_win64_status_badge/)|[![Build Status](http://ci.maidsafe.net:8080/buildStatus/icon?job=maidsafe_types_osx_status_badge)](http://ci.maidsafe.net:8080/job/maidsafe_types_osx_status_badge/)|[![Coverage Status](https://coveralls.io/repos/maidsafe/maidsafe_types/badge.svg)](https://coveralls.io/r/maidsafe/maidsafe_types)|[![Stories in Ready](https://badge.waffle.io/maidsafe/maidsafe_types.png?label=ready&title=Ready)](https://waffle.io/maidsafe/maidsafe_types) 16 | 17 | 18 | | [API Documentation - master branch](http://maidsafe.net/maidsafe_types/master) | [SAFE Network System Documention](http://systemdocs.maidsafe.net) | [MaidSafe website](http://maidsafe.net) | [Safe Community site](https://forum.safenetwork.io) | 19 | |:------:|:-------:|:-------:|:-------:| 20 | 21 | #Overview 22 | 23 | The maidsafe_type library defines all types of data stored on maidsafe network. MaidSafe network enables the user of the data to verify the integrity of data, whether it is mutbale or immutable. 24 | 25 | ## Data 26 | 27 | ### Immutable Data 28 | On MaidSafe network, most data are represented as Immutable Data. The integrity of the contents of an Immutable Data can be verified by checking the hash of content to be the address on the network where data is stored. 29 | 30 | ### Structured Data 31 | If data needs to be mutated it is represented as structured data. The structured data can hold a limited history of data updates. 32 | 33 | ## ID 34 | 35 | Id types represent information associated to an identity on the network. The Id types can be secret or public. The secret Id types hold sensitive information and are never stored on network. Each secret Id has a corresponding public Id type which is stored on the network. The secret and public part of the Id are used to offer asymmetric cryptography services. 36 | 37 | ### Secret Revocation Id Type 38 | Secret revocation Id types are never stored on network. These Id types are used on creation of Public Ids and also they can be used to revoke their corresponding public-private keys if is required. 39 | 40 | ### Secret Id Type 41 | Similar to revocation Id types, secret Id types are not stored on network. The secret Id types have private and public part of signing and encryption keys associated to an identity. 42 | 43 | ### Public Id Type 44 | Public Id types represent the public part of the secret Id types and their integrity can be verified by revocation id signed information. Moreover, the address a public id type is located on network is the hash of its contents, which can also be verified. 45 | A public Id type can be revoked by revocation id type, if required. To revoke the public id, the revocation id type sends a signed update request to the public id type. The update is performed to make the hash of the contents not be equal to its address and/or change signature to be not equal to a valid signature. Any further access to the revoked public id type then results in inregrity / validity check. 46 | 47 | ###Pre-requisite: 48 | libsodium is a native dependency for [sodiumxoide](https://github.com/dnaq/sodiumoxide). Thus, install sodium by following the instructions [here](http://doc.libsodium.org/installation/README.html). 49 | 50 | For windows, download and use the [prebuilt mingw library](https://download.libsodium.org/libsodium/releases/libsodium-1.0.2-mingw.tar.gz). 51 | Extract and place the libsodium.a file in "bin\x86_64-pc-windows-gnu" for 64bit System or "bin\i686-pc-windows-gnu" for a 32bit system. 52 | 53 | #Todo Items 54 | 55 | ## [0.2.4] 56 | - [ ] Add MSID type for shared data. 57 | -------------------------------------------------------------------------------- /src/coin/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 MaidSafe.net limited. 2 | // 3 | // This SAFE Network Software is licensed to you under (1) the MaidSafe.net Commercial License, 4 | // version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which 5 | // licence you accepted on initial access to the Software (the "Licences"). 6 | // 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. 10 | // 11 | // Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed 12 | // under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. 14 | // 15 | // Please review the Licences for the specific language governing permissions and limitations 16 | // relating to use of the SAFE Network Software. 17 | 18 | mod safecoin; 19 | 20 | pub use self::safecoin::*; 21 | 22 | #[test] 23 | fn dummy() {} 24 | -------------------------------------------------------------------------------- /src/coin/safecoin.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 MaidSafe.net limited. 2 | // 3 | // This SAFE Network Software is licensed to you under (1) the MaidSafe.net Commercial License, 4 | // version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which 5 | // licence you accepted on initial access to the Software (the "Licences"). 6 | // 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. 10 | // 11 | // Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed 12 | // under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. 14 | // 15 | // Please review the Licences for the specific language governing permissions and limitations 16 | // relating to use of the SAFE Network Software. 17 | 18 | use cbor; 19 | use cbor::CborTagEncode; 20 | use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; 21 | use helper::*; 22 | use routing::NameType; 23 | use routing::sendable::Sendable; 24 | use routing::types::Signature; 25 | use std::fmt; 26 | // use sodiumoxide::crypto::sign::{SecretKey, sign_detached}; 27 | use TypeTag; 28 | 29 | /// TypeTag for SafeCoin 30 | #[derive(Clone)] 31 | pub struct SafeCoinTypeTag; 32 | 33 | impl TypeTag for SafeCoinTypeTag { 34 | fn type_tag(&self) -> u64 { 35 | return 256; 36 | } 37 | } 38 | 39 | /// SafeCoin 40 | #[derive(Clone)] 41 | pub struct SafeCoin { 42 | type_tag: SafeCoinTypeTag, 43 | name: NameType, 44 | owners: Vec, 45 | previous_owners: Vec, 46 | signatures: Vec 47 | } 48 | 49 | impl SafeCoin { 50 | /// Construct using new() 51 | pub fn new(name: NameType, owners: Vec, signatures: Vec) -> SafeCoin { 52 | SafeCoin { type_tag: SafeCoinTypeTag, 53 | name: name, 54 | owners: owners.clone(), 55 | previous_owners: owners, 56 | signatures: signatures 57 | } 58 | } 59 | } 60 | 61 | impl Sendable for SafeCoin { 62 | fn name(&self) -> NameType { 63 | self.name.clone() 64 | } 65 | 66 | fn type_tag(&self) -> u64 { 67 | self.type_tag.type_tag().clone() 68 | } 69 | 70 | fn serialised_contents(&self) -> Vec { 71 | let mut e = cbor::Encoder::from_memory(); 72 | e.encode(&[&self]).unwrap(); 73 | e.into_bytes() 74 | } 75 | 76 | fn refresh(&self)->bool { 77 | false 78 | } 79 | 80 | fn merge(&self, _: Vec>) -> Option> { None } 81 | } 82 | 83 | impl PartialEq for SafeCoin { 84 | fn eq(&self, other: &SafeCoin) -> bool { 85 | &self.type_tag.type_tag() == &other.type_tag.type_tag() && 86 | self.name == other.name && 87 | self.owners == other.owners && 88 | self.previous_owners == other.previous_owners && 89 | self.signatures == other.signatures 90 | } 91 | } 92 | 93 | impl fmt::Debug for SafeCoin { 94 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 95 | write!(f, "SafeCoin {{ type_tag:{:?}, name:{:?}, owners:{:?}, previous_owners:{:?}, signatures:{:?}}}", 96 | self.type_tag.type_tag(), self.name, self.owners, self.previous_owners, self.signatures) 97 | } 98 | } 99 | 100 | impl Encodable for SafeCoin { 101 | fn encode(&self, e: &mut E) -> Result<(), E::Error> { 102 | CborTagEncode::new(5483_003, &(&self.name, &self.owners, &self.previous_owners, &self.signatures)).encode(e) 103 | } 104 | } 105 | 106 | impl Decodable for SafeCoin { 107 | fn decode(d: &mut D) -> Result { 108 | try!(d.read_u64()); 109 | let (name, owners, previous_owners, signatures) = try!(Decodable::decode(d)); 110 | let safecoin = SafeCoin { type_tag: SafeCoinTypeTag, 111 | name: name, 112 | owners: owners, 113 | previous_owners: previous_owners, 114 | signatures: signatures 115 | }; 116 | Ok(safecoin) 117 | } 118 | } 119 | 120 | #[cfg(test)] 121 | mod test { 122 | use super::*; 123 | use routing::NameType; 124 | use routing::types::{vector_as_u8_64_array, generate_random_vec_u8}; 125 | use routing::types::Signature; 126 | use routing::sendable::Sendable; 127 | use Random; 128 | 129 | impl Random for SafeCoin { 130 | fn generate_random() -> SafeCoin { 131 | let name = NameType::new(vector_as_u8_64_array(generate_random_vec_u8(64))); 132 | let mut owners = Vec::::new(); 133 | owners.push(NameType::new(vector_as_u8_64_array(generate_random_vec_u8(64)))); 134 | let mut previous_owners = Vec::::new(); 135 | previous_owners.push(NameType::new(vector_as_u8_64_array(generate_random_vec_u8(64)))); 136 | let mut signatures = Vec::::new(); 137 | signatures.push(Signature { signature: generate_random_vec_u8(64)}); 138 | 139 | SafeCoin { 140 | type_tag: SafeCoinTypeTag, 141 | name: name, 142 | owners: owners, 143 | previous_owners: previous_owners, 144 | signatures: signatures 145 | } 146 | } 147 | } 148 | 149 | #[test] 150 | fn create_safecoin() { 151 | let safecoin = SafeCoin::generate_random(); 152 | assert_eq!(safecoin, safecoin); 153 | assert_eq!(safecoin.type_tag(), 256u64); 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /src/data/immutable_data.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 MaidSafe.net limited. 2 | // 3 | // This SAFE Network Software is licensed to you under (1) the MaidSafe.net Commercial License, 4 | // version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which 5 | // licence you accepted on initial access to the Software (the "Licences"). 6 | // 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. 10 | // 11 | // Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed 12 | // under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. 14 | // 15 | // Please review the Licences for the specific language governing permissions and limitations 16 | // relating to use of the SAFE Network Software. 17 | 18 | use cbor; 19 | use cbor::CborTagEncode; 20 | use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; 21 | use routing::NameType; 22 | use routing::sendable::Sendable; 23 | use sodiumoxide::crypto; 24 | use std::fmt; 25 | use TypeTag; 26 | 27 | /// TypeTag for ImmutableData 28 | #[derive(Clone)] 29 | pub struct ImmutableDataTypeTag; 30 | /// TypeTag for ImmutableDataBackup 31 | #[derive(Clone)] 32 | pub struct ImmutableDataBackupTypeTag; 33 | /// TypeTag for ImmutableDataSacrificial 34 | #[derive(Clone)] 35 | pub struct ImmutableDataSacrificialTypeTag; 36 | 37 | impl TypeTag for ImmutableDataTypeTag { 38 | fn type_tag(&self) -> u64 { 39 | ::data_tags::IMMUTABLE_DATA_TAG 40 | } 41 | } 42 | 43 | impl TypeTag for ImmutableDataBackupTypeTag { 44 | fn type_tag(&self) -> u64 { 45 | ::data_tags::IMMUTABLE_DATA_BACKUP_TAG 46 | } 47 | } 48 | 49 | impl TypeTag for ImmutableDataSacrificialTypeTag { 50 | fn type_tag(&self) -> u64 { 51 | ::data_tags::IMMUTABLE_DATA_SACRIFICIAL_TAG 52 | } 53 | } 54 | 55 | /// ImmutableData 56 | #[derive(Clone)] 57 | pub struct ImmutableData { 58 | type_tag: ImmutableDataTypeTag, 59 | value: Vec, 60 | } 61 | 62 | impl Sendable for ImmutableData { 63 | fn name(&self) -> NameType { 64 | let digest = crypto::hash::sha512::hash(&self.value); 65 | NameType(digest.0) 66 | } 67 | 68 | fn type_tag(&self) -> u64 { 69 | self.type_tag.type_tag().clone() 70 | } 71 | 72 | fn serialised_contents(&self) -> Vec { 73 | let mut e = cbor::Encoder::from_memory(); 74 | e.encode(&[&self]).unwrap(); 75 | e.into_bytes() 76 | } 77 | 78 | fn refresh(&self)->bool { 79 | false 80 | } 81 | 82 | fn merge(&self, _: Vec>) -> Option> { None } 83 | } 84 | 85 | impl PartialEq for ImmutableData { 86 | fn eq(&self, other: &ImmutableData) -> bool { 87 | &self.type_tag.type_tag() == &other.type_tag.type_tag() && 88 | self.value == other.value 89 | } 90 | } 91 | 92 | impl fmt::Debug for ImmutableData { 93 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 94 | write!(f, "ImmutableData( type_tag:{}, name: {:?}, value: {:?} )", 95 | self.type_tag.type_tag(), self.name(), self.value) 96 | } 97 | } 98 | 99 | impl ImmutableData { 100 | /// Creates a new instance of ImmutableData 101 | pub fn new(value: Vec) -> ImmutableData { 102 | ImmutableData { 103 | type_tag: ImmutableDataTypeTag, 104 | value: value, 105 | } 106 | } 107 | 108 | /// Returns the value 109 | pub fn value(&self) -> &Vec { 110 | &self.value 111 | } 112 | } 113 | 114 | impl Encodable for ImmutableData { 115 | fn encode(&self, e: &mut E)->Result<(), E::Error> { 116 | CborTagEncode::new(::data_tags::IMMUTABLE_DATA_TAG, &(&self.value)).encode(e) 117 | } 118 | } 119 | 120 | impl Decodable for ImmutableData { 121 | fn decode(d: &mut D)->Result { 122 | let value = try!(Decodable::decode(d)); 123 | Ok(ImmutableData::new(value)) 124 | } 125 | } 126 | 127 | 128 | /// ImmutableDataBackup 129 | #[derive(Clone)] 130 | pub struct ImmutableDataBackup { 131 | type_tag: ImmutableDataBackupTypeTag, 132 | value: Vec, 133 | } 134 | 135 | impl Sendable for ImmutableDataBackup { 136 | fn name(&self) -> NameType { 137 | let digest = crypto::hash::sha512::hash(&crypto::hash::sha512::hash(&self.value).0); 138 | NameType(digest.0) 139 | } 140 | 141 | fn type_tag(&self) -> u64 { 142 | self.type_tag.type_tag().clone() 143 | } 144 | 145 | fn serialised_contents(&self)->Vec { 146 | let mut e = cbor::Encoder::from_memory(); 147 | e.encode(&[&self]).unwrap(); 148 | e.into_bytes() 149 | } 150 | 151 | fn refresh(&self)->bool { 152 | false 153 | } 154 | 155 | fn merge(&self, _: Vec>) -> Option> { None } 156 | } 157 | 158 | impl PartialEq for ImmutableDataBackup { 159 | fn eq(&self, other: &ImmutableDataBackup) -> bool { 160 | &self.type_tag.type_tag() == &other.type_tag.type_tag() && 161 | self.value == other.value 162 | } 163 | } 164 | 165 | impl fmt::Debug for ImmutableDataBackup { 166 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 167 | write!(f, "ImmutableDataBackup( type_tag:{}, name: {:?}, value: {:?} )", 168 | self.type_tag.type_tag(), self.name(), self.value) 169 | } 170 | } 171 | 172 | impl ImmutableDataBackup { 173 | /// Creates a new instance of ImmutableDataBackup 174 | pub fn new(immutable_data: ImmutableData) -> ImmutableDataBackup { 175 | ImmutableDataBackup { 176 | type_tag: ImmutableDataBackupTypeTag, 177 | value: immutable_data.value().clone(), 178 | } 179 | } 180 | 181 | /// Returns the value 182 | pub fn value(&self) -> &Vec { 183 | &self.value 184 | } 185 | } 186 | 187 | impl Encodable for ImmutableDataBackup { 188 | fn encode(&self, e: &mut E)->Result<(), E::Error> { 189 | CborTagEncode::new(::data_tags::IMMUTABLE_DATA_BACKUP_TAG, &(&self.value)).encode(e) 190 | } 191 | } 192 | 193 | impl Decodable for ImmutableDataBackup { 194 | fn decode(d: &mut D)->Result { 195 | let value = try!(Decodable::decode(d)); 196 | Ok(ImmutableDataBackup::new(ImmutableData::new(value))) 197 | } 198 | } 199 | 200 | 201 | /// ImmutableDataSacrificial 202 | #[derive(Clone)] 203 | pub struct ImmutableDataSacrificial { 204 | type_tag: ImmutableDataSacrificialTypeTag, 205 | value: Vec, 206 | } 207 | 208 | impl Sendable for ImmutableDataSacrificial { 209 | fn name(&self) -> NameType { 210 | let digest = crypto::hash::sha512::hash( 211 | &crypto::hash::sha512::hash(&crypto::hash::sha512::hash(&self.value).0).0); 212 | NameType(digest.0) 213 | } 214 | 215 | fn type_tag(&self) -> u64 { 216 | self.type_tag.type_tag().clone() 217 | } 218 | 219 | fn serialised_contents(&self)->Vec { 220 | let mut e = cbor::Encoder::from_memory(); 221 | e.encode(&[&self]).unwrap(); 222 | e.into_bytes() 223 | } 224 | 225 | fn refresh(&self)->bool { 226 | false 227 | } 228 | 229 | fn merge(&self, _: Vec>) -> Option> { None } 230 | } 231 | 232 | impl PartialEq for ImmutableDataSacrificial { 233 | fn eq(&self, other: &ImmutableDataSacrificial) -> bool { 234 | &self.type_tag.type_tag() == &other.type_tag.type_tag() && 235 | self.value == other.value 236 | } 237 | } 238 | 239 | impl fmt::Debug for ImmutableDataSacrificial { 240 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 241 | write!(f, "ImmutableDataSacrificial( type_tag:{}, name: {:?}, value: {:?} )", 242 | self.type_tag.type_tag(), self.name(), self.value) 243 | } 244 | } 245 | 246 | impl ImmutableDataSacrificial { 247 | /// Creates a new instance of ImmutableDataSacrificial from ImmutableData type 248 | pub fn new(immutable_data: ImmutableData) -> ImmutableDataSacrificial { 249 | ImmutableDataSacrificial { 250 | type_tag: ImmutableDataSacrificialTypeTag, 251 | value: immutable_data.value().clone(), 252 | } 253 | } 254 | 255 | /// Returns the value 256 | pub fn value(&self) -> &Vec { 257 | &self.value 258 | } 259 | } 260 | 261 | impl Encodable for ImmutableDataSacrificial { 262 | fn encode(&self, e: &mut E)->Result<(), E::Error> { 263 | CborTagEncode::new(::data_tags::IMMUTABLE_DATA_SACRIFICIAL_TAG, &(&self.value)).encode(e) 264 | } 265 | } 266 | 267 | impl Decodable for ImmutableDataSacrificial { 268 | fn decode(d: &mut D)->Result { 269 | let value = try!(Decodable::decode(d)); 270 | Ok(ImmutableDataSacrificial::new(ImmutableData::new(value))) 271 | } 272 | } 273 | 274 | 275 | #[cfg(test)] 276 | mod test { 277 | extern crate rand; 278 | 279 | use super::*; 280 | use self::rand::Rng; 281 | use cbor::{ Encoder, Decoder}; 282 | use rustc_serialize::{Decodable, Encodable}; 283 | use Random; 284 | use routing::sendable::Sendable; 285 | use routing::types::array_as_vector; 286 | use sodiumoxide::crypto; 287 | 288 | #[allow(unused_variables)] 289 | impl Random for ImmutableData { 290 | fn generate_random() -> ImmutableData { 291 | let size = 64; 292 | let mut data = Vec::with_capacity(size); 293 | let mut rng = rand::thread_rng(); 294 | for i in 0..size { 295 | data.push(rng.gen()); 296 | } 297 | ImmutableData::new(data) 298 | } 299 | } 300 | 301 | #[test] 302 | fn creation() { 303 | use rustc_serialize::hex::ToHex; 304 | 305 | let value = "immutable data value".to_string().into_bytes(); 306 | 307 | let immutable_data = ImmutableData::new(value); 308 | let immutable_data_name = immutable_data.name().0.as_ref().to_hex(); 309 | let expected_immutable_data_name = 310 | "9f1c9e526f47e36d782de464ea9df0a31a5c19c321f2a5d9c8faacdda4d59abc\ 311 | 713445c8c853e1842d7c2c2311650df1ee24107371935b6be88a10cbf4cd2f8f"; 312 | assert_eq!(&expected_immutable_data_name, &immutable_data_name); 313 | 314 | let immutable_data_backup = ImmutableDataBackup::new(immutable_data.clone()); 315 | let immutable_data_backup_name = immutable_data_backup.name().0.as_ref().to_hex(); 316 | let expected_immutable_data_backup_name = 317 | "8c6377c848321dd3c6886a53b1a2bc28a5bc8ce35ac85d10d75467a5df9434ab\ 318 | aee19ce2c710507533d306302b165b4387458b752579fc15e520daaf984a2e38"; 319 | assert_eq!(&expected_immutable_data_backup_name, &immutable_data_backup_name); 320 | 321 | let immutable_data_sacrificial = ImmutableDataSacrificial::new(immutable_data); 322 | let immutable_data_sacrificial_name = immutable_data_sacrificial.name().0.as_ref().to_hex(); 323 | let expected_immutable_data_sacrificial_name = 324 | "ecb6c761c35d4da33b25057fbf6161e68711f9e0c11122732e62661340e630d3\ 325 | c59f7c165f4862d51db5254a38ab9b15a9b8af431e8500a4eb558b9136bd4135"; 326 | assert_eq!(&expected_immutable_data_sacrificial_name, &immutable_data_sacrificial_name); 327 | } 328 | 329 | #[test] 330 | fn serialisation() { 331 | let immutable_data = ImmutableData::generate_random(); 332 | let immutable_data_backup = ImmutableDataBackup::new(immutable_data.clone()); 333 | let immutable_data_sacrificial = ImmutableDataSacrificial::new(immutable_data.clone()); 334 | 335 | // ImmutableData 336 | let mut immutable_data_encoder = Encoder::from_memory(); 337 | immutable_data_encoder.encode(&[&immutable_data]).unwrap(); 338 | let mut immutable_data_decoder = 339 | Decoder::from_bytes(immutable_data_encoder.as_bytes()); 340 | match immutable_data_decoder.decode().next().unwrap().unwrap() { 341 | ::test_utils::Parser::ImmutData(decoded_immutable_data) => assert_eq!(immutable_data, decoded_immutable_data), 342 | _ => panic!("Unexpected!"), 343 | } 344 | 345 | // ImmutableDataBackup 346 | let mut immutable_data_backup_encoder = Encoder::from_memory(); 347 | immutable_data_backup_encoder.encode(&[&immutable_data_backup]).unwrap(); 348 | let mut immutable_data_backup_decoder = 349 | Decoder::from_bytes(immutable_data_backup_encoder.as_bytes()); 350 | match immutable_data_backup_decoder.decode().next().unwrap().unwrap() { 351 | ::test_utils::Parser::ImmutDataBkup(decoded_immutable_data_backup) => assert_eq!(immutable_data_backup, decoded_immutable_data_backup), 352 | _ => panic!("Unexpected!"), 353 | } 354 | 355 | // ImmutableDataSacrificial 356 | let mut immutable_data_sacrificial_encoder = Encoder::from_memory(); 357 | immutable_data_sacrificial_encoder.encode(&[&immutable_data_sacrificial]).unwrap(); 358 | let mut immutable_data_sacrificial_decoder = 359 | Decoder::from_bytes(immutable_data_sacrificial_encoder.as_bytes()); 360 | match immutable_data_sacrificial_decoder.decode().next().unwrap().unwrap() { 361 | ::test_utils::Parser::ImmutDataSacrificial(decoded_immutable_data_sacrificial) => assert_eq!(immutable_data_sacrificial, decoded_immutable_data_sacrificial), 362 | _ => panic!("Unexpected!"), 363 | } 364 | } 365 | 366 | #[test] 367 | fn equality() { 368 | let immutable_data_first = ImmutableData::generate_random(); 369 | let immutable_data_second = ImmutableData::generate_random(); 370 | let immutable_data_second_clone = immutable_data_second.clone(); 371 | 372 | assert!(immutable_data_first != immutable_data_second); 373 | assert!(immutable_data_second_clone == immutable_data_second); 374 | 375 | let immutable_data_backup_first = ImmutableDataBackup::new(immutable_data_first.clone()); 376 | let immutable_data_backup_second = ImmutableDataBackup::new(immutable_data_second.clone()); 377 | let immutable_data_backup_second_clone = immutable_data_backup_second.clone(); 378 | 379 | assert!(immutable_data_backup_first != immutable_data_backup_second); 380 | assert!(immutable_data_backup_second_clone == immutable_data_backup_second); 381 | 382 | let immutable_data_sacrificial_first = ImmutableDataSacrificial::new(immutable_data_first.clone()); 383 | let immutable_data_sacrificial_second = ImmutableDataSacrificial::new(immutable_data_second.clone()); 384 | let immutable_data_sacrificial_second_clone = immutable_data_sacrificial_second.clone(); 385 | 386 | assert!(immutable_data_sacrificial_first != immutable_data_sacrificial_second); 387 | assert!(immutable_data_sacrificial_second_clone == immutable_data_sacrificial_second); 388 | } 389 | 390 | #[test] 391 | fn invariant_check() { 392 | let immutable_data = ImmutableData::generate_random(); 393 | let immutable_data_name = array_as_vector(&immutable_data.name().get_id()); 394 | let hash_value = array_as_vector(&crypto::hash::sha512::hash(&immutable_data.value()).0); 395 | 396 | assert_eq!(immutable_data_name, hash_value); 397 | } 398 | } 399 | -------------------------------------------------------------------------------- /src/data/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 MaidSafe.net limited. 2 | // 3 | // This SAFE Network Software is licensed to you under (1) the MaidSafe.net Commercial License, 4 | // version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which 5 | // licence you accepted on initial access to the Software (the "Licences"). 6 | // 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. 10 | // 11 | // Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed 12 | // under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. 14 | // 15 | // Please review the Licences for the specific language governing permissions and limitations 16 | // relating to use of the SAFE Network Software. 17 | 18 | mod structured_data; 19 | mod immutable_data; 20 | 21 | pub use self::structured_data::*; 22 | pub use self::immutable_data::*; 23 | 24 | #[test] 25 | fn dummy() { 26 | } 27 | -------------------------------------------------------------------------------- /src/data/structured_data.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 MaidSafe.net limited. 2 | // 3 | // This SAFE Network Software is licensed to you under (1) the MaidSafe.net Commercial License, 4 | // version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which 5 | // licence you accepted on initial access to the Software (the "Licences"). 6 | // 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. 10 | // 11 | // Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed 12 | // under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. 14 | // 15 | // Please review the Licences for the specific language governing permissions and limitations 16 | // relating to use of the SAFE Network Software. 17 | 18 | use std::cmp; 19 | 20 | use cbor; 21 | use cbor::CborTagEncode; 22 | use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; 23 | use routing::NameType; 24 | use routing::sendable::Sendable; 25 | use TypeTag; 26 | 27 | /// TypeTag for StructuredData 28 | #[derive(Clone, PartialEq, Debug)] 29 | pub struct StructuredDataTypeTag; 30 | 31 | impl TypeTag for StructuredDataTypeTag { 32 | fn type_tag(&self) -> u64 { 33 | ::data_tags::STRUCTURED_DATA_TAG 34 | } 35 | } 36 | 37 | /// StructuredData 38 | #[derive(Clone, PartialEq, Debug)] 39 | pub struct StructuredData { 40 | type_tag: StructuredDataTypeTag, 41 | name: NameType, 42 | owner: NameType, 43 | value: Vec, 44 | } 45 | 46 | impl Sendable for StructuredData { 47 | fn name(&self) -> NameType { 48 | self.name.clone() 49 | } 50 | 51 | fn type_tag(&self) -> u64 { 52 | self.type_tag.type_tag().clone() 53 | } 54 | 55 | fn serialised_contents(&self)->Vec { 56 | let mut e = cbor::Encoder::from_memory(); 57 | e.encode(&[&self]).unwrap(); 58 | e.into_bytes() 59 | } 60 | 61 | fn owner(&self) -> Option { 62 | Some(self.owner.clone()) 63 | } 64 | 65 | fn refresh(&self)->bool { 66 | false 67 | } 68 | 69 | fn merge(&self, sdvs: Vec>) -> Option> { 70 | let mut merged_value = self.value.clone(); 71 | for itr in sdvs { 72 | let mut d_sdv = cbor::Decoder::from_bytes(&itr.serialised_contents()[..]); 73 | let sdv: StructuredData = d_sdv.decode().next().unwrap().unwrap(); 74 | if sdv.name() == self.name() { 75 | let mut merging = Vec::new(); 76 | let incoming_value = sdv.value(); 77 | for i in 0..cmp::min(merged_value.len(), incoming_value.len()) { 78 | if merged_value[i] == incoming_value[i] { 79 | merging.push(merged_value[i].clone()); 80 | } else { 81 | break; 82 | } 83 | } 84 | merged_value = merging; 85 | } 86 | } 87 | if merged_value.len() == 0 { 88 | None 89 | } else { 90 | Some(Box::new(StructuredData::new(self.name.clone(), self.owner.clone(), merged_value))) 91 | } 92 | } 93 | } 94 | 95 | impl StructuredData { 96 | /// An instance of the StructuredData can be created by invoking the new() 97 | pub fn new(name: NameType, owner: NameType, value: Vec) -> StructuredData { 98 | StructuredData {type_tag: StructuredDataTypeTag, name: name, owner: owner, value: value} 99 | } 100 | 101 | /// Returns the value 102 | pub fn value(&self) -> Vec { 103 | self.value.clone() 104 | } 105 | 106 | /// Sets the value 107 | pub fn set_value(&mut self, data: Vec) { 108 | self.value = data; 109 | } 110 | } 111 | 112 | impl Encodable for StructuredData { 113 | fn encode(&self, e: &mut E) -> Result<(), E::Error> { 114 | CborTagEncode::new(::data_tags::STRUCTURED_DATA_TAG, &(&self.name, &self.owner, &self.value)).encode(e) 115 | } 116 | } 117 | 118 | impl Decodable for StructuredData { 119 | fn decode(d: &mut D) -> Result { 120 | let (name, owner, value) = try!(Decodable::decode(d)); 121 | let structured = StructuredData { 122 | type_tag: StructuredDataTypeTag, 123 | name: name, 124 | owner: owner, 125 | value: value 126 | }; 127 | Ok(structured) 128 | } 129 | } 130 | #[cfg(test)] 131 | mod test { 132 | extern crate rand; 133 | 134 | use super::*; 135 | use cbor::{ Encoder, Decoder }; 136 | use rustc_serialize::{Decodable, Encodable}; 137 | use routing; 138 | use routing::NameType; 139 | use routing::sendable::Sendable; 140 | use Random; 141 | 142 | impl Random for StructuredData { 143 | fn generate_random() -> StructuredData { 144 | let size = rand::random::() % 100 + 1; 145 | let mut value = Vec::::with_capacity(size); 146 | for _ in 0..size { 147 | value.push(routing::test_utils::Random::generate_random()); 148 | } 149 | StructuredData { 150 | type_tag: StructuredDataTypeTag, 151 | name: routing::test_utils::Random::generate_random(), 152 | owner: routing::test_utils::Random::generate_random(), 153 | value: value, 154 | } 155 | } 156 | } 157 | 158 | #[test] 159 | fn creation() { 160 | let structured_data = StructuredData::generate_random(); 161 | let data = StructuredData::new(structured_data.name(), structured_data.owner().unwrap(), structured_data.value()); 162 | assert_eq!(data, structured_data); 163 | assert_eq!(structured_data.type_tag(), ::data_tags::STRUCTURED_DATA_TAG); 164 | } 165 | 166 | #[test] 167 | fn serialisation_structured_data() { 168 | let obj_before = StructuredData::generate_random(); 169 | let obj_before_clone = obj_before.clone(); 170 | let obj_before1 = StructuredData::generate_random(); 171 | 172 | let mut e = Encoder::from_memory(); 173 | e.encode(&[&obj_before]).unwrap(); 174 | 175 | let mut d = Decoder::from_bytes(e.as_bytes()); 176 | match d.decode().next().unwrap().unwrap() { 177 | ::test_utils::Parser::StructData(obj_after) => { 178 | assert_eq!(obj_before, obj_after); 179 | assert!(!(obj_before != obj_before_clone)); 180 | assert!(obj_before != obj_before1); 181 | }, 182 | _ => panic!("Unexpected!"), 183 | } 184 | } 185 | } 186 | -------------------------------------------------------------------------------- /src/helper.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 MaidSafe.net limited. 2 | // 3 | // This SAFE Network Software is licensed to you under (1) the MaidSafe.net Commercial License, 4 | // version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which 5 | // licence you accepted on initial access to the Software (the "Licences"). 6 | // 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. 10 | // 11 | // Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed 12 | // under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. 14 | // 15 | // Please review the Licences for the specific language governing permissions and limitations 16 | // relating to use of the SAFE Network Software. 17 | 18 | use sodiumoxide::crypto; 19 | use routing::NameType; 20 | 21 | /// 22 | /// Returns true if both slices are equal in length, and have equal contents 23 | /// 24 | pub fn slice_equal(lhs: &[T], rhs: &[T]) -> bool { 25 | lhs.len() == rhs.len() && lhs.iter().zip(rhs.iter()).all(|(a, b)| a == b) 26 | } 27 | 28 | /// 29 | /// Convert a container to an array. If the container is not the exact size specified, None is 30 | /// returned. Otherwise, all of the elements are moved into the array. 31 | /// 32 | /// ``` 33 | /// let mut data = Vec::::new(); 34 | /// data.push(1); 35 | /// data.push(2); 36 | /// assert!(convert_to_array(data, 2).is_some()); 37 | /// assert!(convert_to_array(data, 3).is_none()); 38 | /// ``` 39 | macro_rules! convert_to_array { 40 | ($container:ident, $size:expr) => {{ 41 | if $container.len() != $size { 42 | None 43 | } else { 44 | use std::mem; 45 | let mut arr : [_; $size] = unsafe { mem::uninitialized() }; 46 | for element in $container.into_iter().enumerate() { 47 | let old_val = mem::replace(&mut arr[element.0], element.1); 48 | mem::forget(old_val); 49 | } 50 | Some(arr) 51 | } 52 | }}; 53 | } 54 | 55 | /// 56 | /// Return NameType using Public signing & encryption keys 57 | /// 58 | pub fn name(public_keys: &(crypto::sign::PublicKey, crypto::box_::PublicKey), type_tag: u64, 59 | signature: &crypto::sign::Signature) -> NameType { 60 | let combined_iter = (public_keys.0).0.into_iter().chain((public_keys.1).0.into_iter()); 61 | let mut combined: Vec = Vec::new(); 62 | for iter in combined_iter { 63 | combined.push(*iter); 64 | } 65 | for i in type_tag.to_string().into_bytes().into_iter() { 66 | combined.push(i); 67 | } 68 | for i in 0..crypto::sign::SIGNATUREBYTES { 69 | combined.push(signature.0[i]); 70 | } 71 | NameType(crypto::hash::sha512::hash(&combined).0) 72 | } 73 | 74 | #[cfg(test)] 75 | mod test { 76 | use super::*; 77 | 78 | #[test] 79 | fn compare_u8_equal() { 80 | let data = "some data".to_string().into_bytes(); 81 | assert!(slice_equal(&data, &data)); 82 | 83 | let data_copy = data.clone(); 84 | assert!(slice_equal(&data, &data_copy)); 85 | assert!(slice_equal(&data_copy, &data)); 86 | } 87 | 88 | #[test] 89 | fn compare_u8_not_equal() { 90 | let data1 = "some data".to_string().into_bytes(); 91 | let data2 = "some daty".to_string().into_bytes(); 92 | assert!(!slice_equal(&data1, &data2)); 93 | assert!(!slice_equal(&data2, &data1)); 94 | } 95 | 96 | #[test] 97 | fn compare_u8_unequal_length() { 98 | let data1 = "some dat".to_string().into_bytes(); 99 | let data2 = "some data".to_string().into_bytes(); 100 | assert!(!slice_equal(&data1, &data2)); 101 | assert!(!slice_equal(&data2, &data1)); 102 | } 103 | 104 | #[test] 105 | fn compare_string_equal() { 106 | let one = "some string".to_string(); 107 | let two = "some two".to_string(); 108 | 109 | let mut data = Vec::::with_capacity(2); 110 | data.push(one); 111 | data.push(two); 112 | 113 | assert!(slice_equal(&data, &data)); 114 | 115 | let data2 = data.clone(); 116 | assert!(slice_equal(&data, &data2)); 117 | assert!(slice_equal(&data2, &data)); 118 | } 119 | 120 | #[test] 121 | fn copy_strings_to_array() { 122 | let one = "some string".to_string(); 123 | let two = "some two".to_string(); 124 | 125 | let mut data = Vec::::with_capacity(2); 126 | data.push(one); 127 | data.push(two); 128 | 129 | let data2 = data.clone(); 130 | let result = convert_to_array!(data2, 2).unwrap(); 131 | assert!(slice_equal(&data, &result)); 132 | } 133 | 134 | #[test] 135 | fn copy_strings_to_bad_array() { 136 | let one = "some string".to_string(); 137 | let two = "some two".to_string(); 138 | 139 | let mut data = Vec::::with_capacity(2); 140 | data.push(one); 141 | data.push(two); 142 | 143 | let data2 = data.clone(); 144 | assert!(convert_to_array!(data2, 1).is_none()); 145 | assert!(convert_to_array!(data, 3).is_none()); 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /src/id/id_type.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 MaidSafe.net limited. 2 | // 3 | // This SAFE Network Software is licensed to you under (1) the MaidSafe.net Commercial License, 4 | // version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which 5 | // licence you accepted on initial access to the Software (the "Licences"). 6 | // 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. 10 | // 11 | // Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed 12 | // under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. 14 | // 15 | // Please review the Licences for the specific language governing permissions and limitations 16 | // relating to use of the SAFE Network Software. 17 | 18 | use cbor::CborTagEncode; 19 | use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; 20 | use sodiumoxide::crypto; 21 | use helper::*; 22 | use super::revocation_id_type::*; 23 | use std::fmt; 24 | use routing::NameType; 25 | 26 | /// IdType 27 | /// 28 | /// #Examples 29 | /// ``` 30 | /// use maidsafe_types::{IdType, RevocationIdType, MaidTypeTags}; 31 | /// // Creating new IdType 32 | /// let maid: IdType = IdType::new(&RevocationIdType::new::()); 33 | /// 34 | /// ``` 35 | #[derive(Clone)] 36 | pub struct IdType { 37 | type_tag: u64, 38 | public_keys: (crypto::sign::PublicKey, crypto::box_::PublicKey), 39 | secret_keys: (crypto::sign::SecretKey, crypto::box_::SecretKey) 40 | } 41 | 42 | impl IdType { 43 | /// Invoked to create an instance of IdType 44 | pub fn new(revocation_id: &RevocationIdType) -> IdType { 45 | let asym_keys = crypto::box_::gen_keypair(); 46 | let signing_keys = crypto::sign::gen_keypair(); 47 | 48 | IdType { 49 | type_tag: revocation_id.type_tags().1, 50 | public_keys: (signing_keys.0, asym_keys.0), 51 | secret_keys: (signing_keys.1, asym_keys.1) 52 | } 53 | } 54 | /// Returns name 55 | pub fn name(&self) -> NameType { 56 | let combined_iter = (&self.public_keys.0).0.into_iter().chain((&self.public_keys.1).0.into_iter()); 57 | let mut combined: Vec = Vec::new(); 58 | for iter in combined_iter { 59 | combined.push(*iter); 60 | } 61 | for i in self.type_tag.to_string().into_bytes().into_iter() { 62 | combined.push(i); 63 | } 64 | NameType(crypto::hash::sha512::hash(&combined).0) 65 | } 66 | /// Returns the PublicKeys 67 | pub fn public_keys(&self) -> &(crypto::sign::PublicKey, crypto::box_::PublicKey){ 68 | &self.public_keys 69 | } 70 | /// Returns the PublicKeys 71 | pub fn secret_keys(&self) -> &(crypto::sign::SecretKey, crypto::box_::SecretKey) { 72 | &self.secret_keys 73 | } 74 | /// Signs the data with the SecretKey and returns the Signed data 75 | pub fn sign(&self, data : &[u8]) -> Vec { 76 | return crypto::sign::sign(&data, &self.secret_keys.0) 77 | } 78 | /// Encrypts and authenticates data. It returns a ciphertext and the Nonce. 79 | pub fn seal(&self, data : &[u8], to : &crypto::box_::PublicKey) -> (Vec, crypto::box_::Nonce) { 80 | let nonce = crypto::box_::gen_nonce(); 81 | let sealed = crypto::box_::seal(data, &nonce, &to, &self.secret_keys.1); 82 | return (sealed, nonce); 83 | } 84 | /// Verifies and decrypts the data 85 | pub fn open( 86 | &self, 87 | data : &[u8], 88 | nonce : &crypto::box_::Nonce, 89 | from : &crypto::box_::PublicKey) -> Result, ::CryptoError> { 90 | return crypto::box_::open(&data, &nonce, &from, &self.secret_keys.1).ok_or(::CryptoError::Unknown); 91 | } 92 | } 93 | 94 | impl PartialEq for IdType { 95 | fn eq(&self, other: &IdType) -> bool { 96 | // Private keys are mathematically linked, so just check public keys 97 | &self.type_tag == &other.type_tag && 98 | slice_equal(&self.public_keys.0 .0, &other.public_keys.0 .0) && 99 | slice_equal(&self.public_keys.1 .0, &other.public_keys.1 .0) 100 | } 101 | } 102 | 103 | impl fmt::Debug for IdType { 104 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 105 | write!(f, "IdType {{ type_tag:{}, public_keys: ({:?}, {:?}) }}", self.type_tag, self.public_keys.0 .0.to_vec(), self.public_keys.1 .0.to_vec()) 106 | } 107 | } 108 | 109 | impl Encodable for IdType { 110 | fn encode(&self, e: &mut E)->Result<(), E::Error> { 111 | let (crypto::sign::PublicKey(pub_sign_vec), crypto::box_::PublicKey(pub_asym_vec)) = self.public_keys; 112 | let (crypto::sign::SecretKey(sec_sign_vec), crypto::box_::SecretKey(sec_asym_vec)) = self.secret_keys; 113 | let type_vec = self.type_tag.to_string().into_bytes(); 114 | 115 | CborTagEncode::new(self.type_tag, &( 116 | type_vec, 117 | pub_sign_vec.as_ref(), 118 | pub_asym_vec.as_ref(), 119 | sec_sign_vec.as_ref(), 120 | sec_asym_vec.as_ref())).encode(e) 121 | } 122 | } 123 | 124 | impl Decodable for IdType { 125 | fn decode(d: &mut D)-> Result { 126 | let (tag_type_vec, pub_sign_vec, pub_asym_vec, sec_sign_vec, sec_asym_vec) : (Vec, Vec, Vec, Vec, Vec) = try!(Decodable::decode(d)); 127 | let pub_sign_arr = convert_to_array!(pub_sign_vec, crypto::sign::PUBLICKEYBYTES); 128 | let pub_asym_arr = convert_to_array!(pub_asym_vec, crypto::box_::PUBLICKEYBYTES); 129 | let sec_sign_arr = convert_to_array!(sec_sign_vec, crypto::sign::SECRETKEYBYTES); 130 | let sec_asym_arr = convert_to_array!(sec_asym_vec, crypto::box_::SECRETKEYBYTES); 131 | 132 | if pub_sign_arr.is_none() || pub_asym_arr.is_none() || sec_sign_arr.is_none() || sec_asym_arr.is_none() { 133 | return Err(d.error("Bad IdType size")); 134 | } 135 | 136 | let type_tag: u64 = match String::from_utf8(tag_type_vec) { 137 | Ok(string) => { 138 | match string.parse::() { 139 | Ok(type_tag) => type_tag, 140 | Err(_) => return Err(d.error("Bad Tag Type")) 141 | } 142 | }, 143 | Err(_) => return Err(d.error("Bad Tag Type")) 144 | }; 145 | 146 | Ok(IdType{ type_tag: type_tag, 147 | public_keys:(crypto::sign::PublicKey(pub_sign_arr.unwrap()), crypto::box_::PublicKey(pub_asym_arr.unwrap())), 148 | secret_keys: (crypto::sign::SecretKey(sec_sign_arr.unwrap()), crypto::box_::SecretKey(sec_asym_arr.unwrap())) }) 149 | } 150 | } 151 | 152 | #[cfg(test)] 153 | mod test { 154 | extern crate rand; 155 | 156 | use super::*; 157 | use self::rand::Rng; 158 | use cbor; 159 | use super::super::RevocationIdType; 160 | use sodiumoxide::crypto; 161 | use Random; 162 | use MaidTypeTags; 163 | 164 | impl Random for IdType { 165 | fn generate_random() -> IdType { 166 | IdType::new(&RevocationIdType::new::()) 167 | } 168 | } 169 | 170 | #[test] 171 | fn serialisation_maid() { 172 | use helper::*; 173 | let obj_before = IdType::generate_random(); 174 | 175 | let mut e = cbor::Encoder::from_memory(); 176 | e.encode(&[&obj_before]).unwrap(); 177 | 178 | let mut d = cbor::Decoder::from_bytes(e.as_bytes()); 179 | match d.decode().next().unwrap().unwrap() { 180 | ::test_utils::Parser::Maid(obj_after) => { 181 | let &(crypto::sign::PublicKey(pub_sign_arr_before), crypto::box_::PublicKey(pub_asym_arr_before)) = obj_before.public_keys(); 182 | let &(crypto::sign::PublicKey(pub_sign_arr_after), crypto::box_::PublicKey(pub_asym_arr_after)) = obj_after.public_keys(); 183 | let &(crypto::sign::SecretKey(sec_sign_arr_before), crypto::box_::SecretKey(sec_asym_arr_before)) = &obj_before.secret_keys; 184 | let &(crypto::sign::SecretKey(sec_sign_arr_after), crypto::box_::SecretKey(sec_asym_arr_after)) = &obj_after.secret_keys; 185 | 186 | assert_eq!(pub_sign_arr_before, pub_sign_arr_after); 187 | assert_eq!(pub_asym_arr_before, pub_asym_arr_after); 188 | assert!(slice_equal(&sec_sign_arr_before, &sec_sign_arr_after)); 189 | assert_eq!(sec_asym_arr_before, sec_asym_arr_after); 190 | }, 191 | _ => panic!("Unexpected!"), 192 | } 193 | } 194 | 195 | #[test] 196 | fn generation() { 197 | let maid1 = IdType::generate_random(); 198 | let maid2 = IdType::generate_random(); 199 | let maid2_clone = maid2.clone(); 200 | 201 | assert_eq!(maid2, maid2_clone); 202 | assert!(!(maid2 != maid2_clone)); 203 | assert!(maid1 != maid2); 204 | 205 | let random_bytes = rand::thread_rng().gen_iter::().take(100).collect::>(); 206 | { 207 | let sign1 = maid1.sign(&random_bytes); 208 | let sign2 = maid2.sign(&random_bytes); 209 | assert!(sign1 != sign2); 210 | 211 | assert!(crypto::sign::verify(&sign1, &maid1.public_keys().0).is_some()); 212 | assert!(crypto::sign::verify(&sign2, &maid1.public_keys().0).is_none()); 213 | 214 | assert!(crypto::sign::verify(&sign2, &maid2.public_keys().0).is_some()); 215 | assert!(crypto::sign::verify(&sign2, &maid1.public_keys().0).is_none()); 216 | } 217 | { 218 | let maid3 = IdType::generate_random(); 219 | 220 | let encrypt1 = maid1.seal(&random_bytes, &maid3.public_keys().1); 221 | let encrypt2 = maid2.seal(&random_bytes, &maid3.public_keys().1); 222 | assert!(encrypt1.0 != encrypt2.0); 223 | 224 | assert!(maid3.open(&encrypt1.0, &encrypt1.1, &maid1.public_keys().1).is_ok()); 225 | assert!(maid3.open(&encrypt1.0, &encrypt1.1, &maid2.public_keys().1).is_err()); 226 | 227 | assert!(maid3.open(&encrypt2.0, &encrypt2.1, &maid2.public_keys().1).is_ok()); 228 | assert!(maid3.open(&encrypt2.0, &encrypt2.1, &maid1.public_keys().1).is_err()); 229 | } 230 | } 231 | } 232 | -------------------------------------------------------------------------------- /src/id/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 MaidSafe.net limited. 2 | // 3 | // This SAFE Network Software is licensed to you under (1) the MaidSafe.net Commercial License, 4 | // version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which 5 | // licence you accepted on initial access to the Software (the "Licences"). 6 | // 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. 10 | // 11 | // Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed 12 | // under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. 14 | // 15 | // Please review the Licences for the specific language governing permissions and limitations 16 | // relating to use of the SAFE Network Software. 17 | 18 | /// AnMaid 19 | pub mod revocation_id_type; 20 | /// Maid 21 | pub mod id_type; 22 | /// PublicMaid 23 | pub mod public_id_type; 24 | 25 | pub use self::revocation_id_type::*; 26 | pub use self::id_type::*; 27 | pub use self::public_id_type::*; 28 | #[test] 29 | fn dummy() { 30 | } 31 | -------------------------------------------------------------------------------- /src/id/public_id_type.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 MaidSafe.net limited. 2 | // 3 | // This SAFE Network Software is licensed to you under (1) the MaidSafe.net Commercial License, 4 | // version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which 5 | // licence you accepted on initial access to the Software (the "Licences"). 6 | // 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. 10 | // 11 | // Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed 12 | // under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. 14 | // 15 | // Please review the Licences for the specific language governing permissions and limitations 16 | // relating to use of the SAFE Network Software. 17 | 18 | use cbor; 19 | use cbor::CborTagEncode; 20 | use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; 21 | use sodiumoxide::crypto; 22 | use helper::*; 23 | use routing::NameType; 24 | use routing::sendable::Sendable; 25 | use std::fmt; 26 | use super::revocation_id_type::*; 27 | use super::id_type::*; 28 | 29 | /// PublicIdType 30 | /// 31 | /// #Examples 32 | /// 33 | /// ``` 34 | /// use maidsafe_types::{IdType, RevocationIdType, MaidTypeTags, PublicIdType}; 35 | /// 36 | /// let revocation_maid = RevocationIdType::new::(); 37 | /// let maid = IdType::new(&revocation_maid); 38 | /// let public_maid = PublicIdType::new(&maid, &revocation_maid); 39 | /// ``` 40 | 41 | #[derive(Clone)] 42 | pub struct PublicIdType { 43 | type_tag: u64, 44 | public_keys: (crypto::sign::PublicKey, crypto::box_::PublicKey), 45 | revocation_public_key: crypto::sign::PublicKey, 46 | signature: crypto::sign::Signature 47 | } 48 | 49 | impl Sendable for PublicIdType { 50 | fn name(&self) -> NameType { 51 | name(&self.public_keys, self.type_tag.clone(), &self.signature) 52 | } 53 | 54 | fn type_tag(&self)->u64 { 55 | self.type_tag.clone() 56 | } 57 | 58 | fn serialised_contents(&self)->Vec { 59 | let mut e = cbor::Encoder::from_memory(); 60 | e.encode(&[&self]).unwrap(); 61 | e.into_bytes() 62 | } 63 | 64 | fn refresh(&self)->bool { 65 | false 66 | } 67 | 68 | fn merge(&self, _: Vec>) -> Option> { None } 69 | } 70 | 71 | impl PartialEq for PublicIdType { 72 | fn eq(&self, other: &PublicIdType) -> bool { 73 | &self.type_tag == &other.type_tag && 74 | slice_equal(&self.public_keys.0 .0, &other.public_keys.0 .0) && 75 | slice_equal(&self.public_keys.1 .0, &other.public_keys.1 .0) && 76 | slice_equal(&self.revocation_public_key.0, &other.revocation_public_key.0) && 77 | slice_equal(&self.signature.0, &other.signature.0) 78 | } 79 | } 80 | 81 | impl fmt::Debug for PublicIdType { 82 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 83 | write!(f, "PublicIdType {{ type_tag:{}, public_keys:({:?}, {:?}), revocation_public_key:{:?}, signature:{:?}}}", 84 | self.type_tag, self.public_keys.0 .0.to_vec(), self.public_keys.1 .0.to_vec(), self.revocation_public_key.0.to_vec(), 85 | self.signature.0.to_vec()) 86 | } 87 | } 88 | 89 | impl PublicIdType { 90 | /// An instanstance of the PublicIdType can be created using the new() 91 | pub fn new(id_type: &IdType, revocation_id: &RevocationIdType) -> PublicIdType { 92 | let type_tag = revocation_id.type_tags().2; 93 | let public_keys = id_type.public_keys().clone(); 94 | let revocation_public_key = revocation_id.public_key(); 95 | let combined_iter = (public_keys.0).0.into_iter().chain((public_keys.1).0.into_iter().chain(revocation_public_key.0.into_iter())); 96 | let mut combined: Vec = Vec::new(); 97 | for iter in combined_iter { 98 | combined.push(*iter); 99 | } 100 | for i in type_tag.to_string().into_bytes().into_iter() { 101 | combined.push(i); 102 | } 103 | let message_length = combined.len(); 104 | let signature = revocation_id.sign(&combined).into_iter().skip(message_length).collect::>(); 105 | let signature_arr = convert_to_array!(signature, crypto::sign::SIGNATUREBYTES); 106 | PublicIdType { type_tag: type_tag, public_keys: public_keys, 107 | revocation_public_key: revocation_id.public_key().clone(), 108 | signature: crypto::sign::Signature(signature_arr.unwrap()) } 109 | } 110 | /// Returns the PublicKeys 111 | pub fn public_keys(&self) -> &(crypto::sign::PublicKey, crypto::box_::PublicKey) { 112 | &self.public_keys 113 | } 114 | /// Returns revocation public key 115 | pub fn revocation_public_key(&self) -> &crypto::sign::PublicKey { 116 | &self.revocation_public_key 117 | } 118 | /// Returns the Signature of PublicIdType 119 | pub fn signature(&self) -> &crypto::sign::Signature { 120 | &self.signature 121 | } 122 | } 123 | 124 | impl Encodable for PublicIdType { 125 | fn encode(&self, e: &mut E)->Result<(), E::Error> { 126 | let (crypto::sign::PublicKey(ref pub_sign_vec), crypto::box_::PublicKey(pub_asym_vec)) = self.public_keys; 127 | let crypto::sign::PublicKey(ref revocation_public_key_vec) = self.revocation_public_key; 128 | let crypto::sign::Signature(ref signature) = self.signature; 129 | let type_vec = self.type_tag.to_string().into_bytes(); 130 | CborTagEncode::new(self.type_tag, &( 131 | type_vec, 132 | pub_sign_vec.as_ref(), 133 | pub_asym_vec.as_ref(), 134 | revocation_public_key_vec.as_ref(), 135 | signature.as_ref())).encode(e) 136 | } 137 | } 138 | 139 | impl Decodable for PublicIdType { 140 | fn decode(d: &mut D)-> Result { 141 | let (tag_type_vec, pub_sign_vec, pub_asym_vec, revocation_public_key_vec, signature_vec): (Vec, Vec, Vec, Vec, Vec) = try!(Decodable::decode(d)); 142 | let pub_sign_arr = convert_to_array!(pub_sign_vec, crypto::sign::PUBLICKEYBYTES); 143 | let pub_asym_arr = convert_to_array!(pub_asym_vec, crypto::box_::PUBLICKEYBYTES); 144 | let revocation_public_key_arr = convert_to_array!(revocation_public_key_vec, crypto::box_::PUBLICKEYBYTES); 145 | let signature_arr = convert_to_array!(signature_vec, crypto::sign::SIGNATUREBYTES); 146 | 147 | if pub_sign_arr.is_none() || pub_asym_arr.is_none() || revocation_public_key_arr.is_none() 148 | || signature_arr.is_none() { 149 | return Err(d.error("Bad PublicIdType size")); 150 | } 151 | 152 | let type_tag: u64 = match String::from_utf8(tag_type_vec) { 153 | Ok(string) => { 154 | match string.parse::() { 155 | Ok(type_tag) => type_tag, 156 | Err(_) => return Err(d.error("Bad Tag Type")) 157 | } 158 | }, 159 | Err(_) => return Err(d.error("Bad Tag Type")) 160 | }; 161 | 162 | Ok(PublicIdType{ type_tag: type_tag, 163 | public_keys: (crypto::sign::PublicKey(pub_sign_arr.unwrap()), crypto::box_::PublicKey(pub_asym_arr.unwrap())), 164 | revocation_public_key: crypto::sign::PublicKey(revocation_public_key_arr.unwrap()), 165 | signature: crypto::sign::Signature(signature_arr.unwrap())}) 166 | } 167 | } 168 | 169 | #[cfg(test)] 170 | mod test { 171 | use super::*; 172 | use cbor; 173 | use Random; 174 | use super::super::{ IdType, RevocationIdType }; 175 | use MaidTypeTags; 176 | use MpidTypeTags; 177 | use sodiumoxide::crypto; 178 | use routing::types::array_as_vector; 179 | 180 | impl Random for PublicIdType { 181 | fn generate_random() -> PublicIdType { 182 | let revocation_maid = RevocationIdType::new::(); 183 | let maid = IdType::new(&revocation_maid); 184 | PublicIdType::new(&maid, &revocation_maid) 185 | } 186 | } 187 | 188 | #[test] 189 | fn create_public_mpid() { 190 | let revocation_mpid = RevocationIdType::new::(); 191 | let mpid = IdType::new(&revocation_mpid); 192 | PublicIdType::new(&mpid, &revocation_mpid); 193 | } 194 | 195 | #[test] 196 | fn serialisation_public_maid() { 197 | let obj_before = PublicIdType::generate_random(); 198 | 199 | let mut e = cbor::Encoder::from_memory(); 200 | e.encode(&[&obj_before]).unwrap(); 201 | 202 | let mut d = cbor::Decoder::from_bytes(e.as_bytes()); 203 | match d.decode().next().unwrap().unwrap() { 204 | ::test_utils::Parser::PubMaid(obj_after) => assert_eq!(obj_before, obj_after), 205 | _ => panic!("Unexpected!"), 206 | } 207 | } 208 | 209 | #[test] 210 | fn equality_assertion_public_maid() { 211 | let public_maid_first = PublicIdType::generate_random(); 212 | let public_maid_second = public_maid_first.clone(); 213 | let public_maid_third = PublicIdType::generate_random(); 214 | assert_eq!(public_maid_first, public_maid_second); 215 | assert!(public_maid_first != public_maid_third); 216 | } 217 | 218 | #[test] 219 | fn invariant_check() { 220 | let revocation_maid = RevocationIdType::new::(); 221 | let maid = IdType::new(&revocation_maid); 222 | let public_maid = PublicIdType::new(&maid, &revocation_maid); 223 | let type_tag = public_maid.type_tag; 224 | let public_id_keys = public_maid.public_keys; 225 | let public_revocation_key = public_maid.revocation_public_key; 226 | let combined_keys = (public_id_keys.0).0.into_iter().chain((public_id_keys.1).0 227 | .into_iter().chain(public_revocation_key.0 228 | .into_iter())); 229 | let mut combined = Vec::new(); 230 | 231 | for iter in combined_keys { 232 | combined.push(*iter); 233 | } 234 | for i in type_tag.to_string().into_bytes().into_iter() { 235 | combined.push(i); 236 | } 237 | 238 | let message_length = combined.len(); 239 | let signature = revocation_maid.sign(&combined).into_iter().skip(message_length).collect::>(); 240 | let signature_array = convert_to_array!(signature, crypto::sign::SIGNATUREBYTES); 241 | let signature = crypto::sign::Signature(signature_array.unwrap()); 242 | 243 | assert_eq!(array_as_vector(&signature.0), array_as_vector(&public_maid.signature().0)); 244 | } 245 | } 246 | -------------------------------------------------------------------------------- /src/id/revocation_id_type.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 MaidSafe.net limited. 2 | // 3 | // This SAFE Network Software is licensed to you under (1) the MaidSafe.net Commercial License, 4 | // version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which 5 | // licence you accepted on initial access to the Software (the "Licences"). 6 | // 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. 10 | // 11 | // Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed 12 | // under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. 14 | // 15 | // Please review the Licences for the specific language governing permissions and limitations 16 | // relating to use of the SAFE Network Software. 17 | 18 | use cbor::CborTagEncode; 19 | use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; 20 | use sodiumoxide::crypto; 21 | use helper::*; 22 | use std::fmt; 23 | use IdTypeTags; 24 | use std::mem; 25 | use routing::NameType; 26 | 27 | /// The following key types use the internal cbor tag to identify them and this 28 | /// should be carried through to any json representation if stored on disk 29 | /// 30 | /// RevocationIdType 31 | /// 32 | /// #Examples 33 | /// ``` 34 | /// extern crate sodiumoxide; 35 | /// extern crate maidsafe_types; 36 | /// // Generating public and secret keys using sodiumoxide 37 | /// // Create RevocationIdType 38 | /// let an_maid : maidsafe_types::RevocationIdType = maidsafe_types::RevocationIdType::new::(); 39 | /// ``` 40 | /// 41 | #[derive(Clone)] 42 | pub struct RevocationIdType { 43 | type_tags: (u64, u64, u64), // type tags for revocation, id and public ids 44 | public_key: crypto::sign::PublicKey, 45 | secret_key: crypto::sign::SecretKey 46 | } 47 | 48 | impl PartialEq for RevocationIdType { 49 | fn eq(&self, other: &RevocationIdType) -> bool { 50 | // Private key is mathematically linked, so just check public key 51 | &self.type_tags == &other.type_tags && 52 | slice_equal(&self.public_key.0, &other.public_key.0) 53 | } 54 | } 55 | 56 | 57 | impl fmt::Debug for RevocationIdType { 58 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 59 | let crypto::sign::PublicKey(ref public_key) = self.public_key; 60 | write!(f, "RevocationIdType( type_tags:{:?}, public_key: {:?} )", self.type_tags, public_key) 61 | } 62 | } 63 | 64 | impl RevocationIdType { 65 | /// An instance of RevocationIdType can be created by invoking the new() 66 | /// Default contructed RevocationIdType instance is returned 67 | pub fn new() -> RevocationIdType where TypeTags: IdTypeTags { 68 | let (pub_sign_key, sec_sign_key) = crypto::sign::gen_keypair(); 69 | let type_tags: TypeTags = unsafe { mem::uninitialized() }; 70 | RevocationIdType { 71 | type_tags: (type_tags.revocation_id_type_tag(), type_tags.id_type_tag(), type_tags.public_id_type_tag()), 72 | public_key: pub_sign_key, 73 | secret_key: sec_sign_key 74 | } 75 | } 76 | 77 | /// Returns name 78 | pub fn name(&self) -> NameType { 79 | let combined_iter = self.public_key.0.into_iter(); 80 | let mut combined: Vec = Vec::new(); 81 | for iter in combined_iter { 82 | combined.push(*iter); 83 | } 84 | for i in self.type_tags.0.to_string().into_bytes().into_iter() { 85 | combined.push(i); 86 | } 87 | NameType(crypto::hash::sha512::hash(&combined).0) 88 | } 89 | 90 | /// Returns type tags 91 | pub fn type_tags(&self) -> &(u64, u64, u64) { 92 | &self.type_tags 93 | } 94 | /// Returns type tag 95 | /// TODO needless reference for built in POD 96 | pub fn type_tag(&self) -> &u64 { 97 | &self.type_tags.0 98 | } 99 | /// Returns the SecretKey of the RevocationIdType 100 | pub fn secret_key(&self) -> &crypto::sign::SecretKey { 101 | &self.secret_key 102 | } 103 | /// Returns the PublicKey of the AnMaid 104 | pub fn public_key(&self) -> &crypto::sign::PublicKey { 105 | &self.public_key 106 | } 107 | /// Signs the data with the SecretKey of the AnMaid and recturns the Signed Data 108 | pub fn sign(&self, data : &[u8]) -> Vec { 109 | return crypto::sign::sign(&data, &self.secret_key) 110 | } 111 | } 112 | 113 | fn convert_to_u64(num_vec: Vec) -> Option { 114 | match String::from_utf8(num_vec) { 115 | Ok(string) => { 116 | match string.parse::() { 117 | Ok(type_tag) => Some(type_tag), 118 | Err(_) => None 119 | } 120 | }, 121 | Err(_) => None 122 | } 123 | } 124 | 125 | impl Encodable for RevocationIdType { 126 | fn encode(&self, e: &mut E)->Result<(), E::Error> { 127 | let revocation_type_tag_vec = self.type_tags.0.to_string().into_bytes(); 128 | let id_type_tag_vec = self.type_tags.1.to_string().into_bytes(); 129 | let public_id_type_tag_vec = self.type_tags.2.to_string().into_bytes(); 130 | CborTagEncode::new(*self.type_tag(), 131 | &(revocation_type_tag_vec, 132 | id_type_tag_vec, 133 | public_id_type_tag_vec, 134 | self.public_key.0.as_ref(), self.secret_key.0.as_ref())).encode(e) 135 | } 136 | } 137 | 138 | impl Decodable for RevocationIdType { 139 | fn decode(d: &mut D)-> Result { 140 | let(revocation_type_tag_vec, id_type_tag_vec, public_id_type_tag_vec , pub_sign_vec, sec_sign_vec) : (Vec, Vec, Vec, Vec, Vec) = try!(Decodable::decode(d)); 141 | let pub_sign_arr = convert_to_array!(pub_sign_vec, crypto::sign::PUBLICKEYBYTES); 142 | let sec_sign_arr = convert_to_array!(sec_sign_vec, crypto::sign::SECRETKEYBYTES); 143 | let (revocation_type_tag, id_type_tag, public_id_type_tag) = ( 144 | convert_to_u64(revocation_type_tag_vec), 145 | convert_to_u64(id_type_tag_vec), 146 | convert_to_u64(public_id_type_tag_vec)); 147 | 148 | if pub_sign_arr.is_none() || sec_sign_arr.is_none() || revocation_type_tag.is_none() || 149 | id_type_tag.is_none() || public_id_type_tag.is_none() { 150 | return Err(d.error("Bad RevocationIdType size")); 151 | } 152 | 153 | Ok(RevocationIdType{ type_tags: (revocation_type_tag.unwrap(), id_type_tag.unwrap(), public_id_type_tag.unwrap()), 154 | public_key: crypto::sign::PublicKey(pub_sign_arr.unwrap()), 155 | secret_key: crypto::sign::SecretKey(sec_sign_arr.unwrap()) }) 156 | } 157 | } 158 | 159 | #[cfg(test)] 160 | mod test { 161 | extern crate rand; 162 | 163 | use self::rand::Rng; 164 | use cbor; 165 | use Random; 166 | use sodiumoxide::crypto; 167 | use super::RevocationIdType; 168 | use MaidTypeTags; 169 | use MpidTypeTags; 170 | 171 | impl Random for RevocationIdType { 172 | fn generate_random() -> RevocationIdType { 173 | RevocationIdType::new::() 174 | } 175 | } 176 | 177 | #[test] 178 | fn create_an_mpid() { 179 | let _ = RevocationIdType::new::(); 180 | } 181 | 182 | #[test] 183 | fn serialisation_an_maid() { 184 | let obj_before = RevocationIdType::generate_random(); 185 | let mut e = cbor::Encoder::from_memory(); 186 | e.encode(&[&obj_before]).unwrap(); 187 | 188 | let mut d = cbor::Decoder::from_bytes(e.as_bytes()); 189 | match d.decode().next().unwrap().unwrap() { 190 | ::test_utils::Parser::AnMaid(obj_after) => assert_eq!(obj_before, obj_after), 191 | _ => panic!("Unexpected!"), 192 | } 193 | } 194 | 195 | #[test] 196 | fn equality_assertion_an_maid() { 197 | let first_obj = RevocationIdType::generate_random(); 198 | let second_obj = RevocationIdType::generate_random(); 199 | let cloned_obj = second_obj.clone(); 200 | 201 | assert!(first_obj != second_obj); 202 | assert!(second_obj == cloned_obj); 203 | } 204 | 205 | #[test] 206 | fn generation() { 207 | let maid1 = RevocationIdType::generate_random(); 208 | let maid2 = RevocationIdType::generate_random(); 209 | let maid2_clone = maid2.clone(); 210 | 211 | assert_eq!(maid2, maid2_clone); 212 | assert!(!(maid2 != maid2_clone)); 213 | assert!(maid1 != maid2); 214 | 215 | let random_bytes = rand::thread_rng().gen_iter::().take(100).collect::>(); 216 | { 217 | let sign1 = maid1.sign(&random_bytes); 218 | let sign2 = maid2.sign(&random_bytes); 219 | assert!(sign1 != sign2); 220 | 221 | assert!(crypto::sign::verify(&sign1, &maid1.public_key()).is_some()); 222 | assert!(crypto::sign::verify(&sign2, &maid1.public_key()).is_none()); 223 | 224 | assert!(crypto::sign::verify(&sign2, &maid2.public_key()).is_some()); 225 | assert!(crypto::sign::verify(&sign2, &maid1.public_key()).is_none()); 226 | } 227 | } 228 | } 229 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 MaidSafe.net limited. 2 | // 3 | // This SAFE Network Software is licensed to you under (1) the MaidSafe.net Commercial License, 4 | // version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which 5 | // licence you accepted on initial access to the Software (the "Licences"). 6 | // 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. 10 | // 11 | // Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed 12 | // under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. 14 | // 15 | // Please review the Licences for the specific language governing permissions and limitations 16 | // relating to use of the SAFE Network Software. 17 | 18 | #![crate_name = "maidsafe_types"] 19 | #![crate_type = "lib"] 20 | #![doc(html_logo_url = "http://maidsafe.net/img/Resources/branding/maidsafe_logo.fab2.png", 21 | html_favicon_url = "http://maidsafe.net/img/favicon.ico", 22 | html_root_url = "http://maidsafe.github.io/maidsafe/maidsafe_types/")] 23 | 24 | #![forbid(bad_style, warnings)] 25 | 26 | #![deny(deprecated, improper_ctypes, missing_docs, non_shorthand_field_patterns, 27 | overflowing_literals, plugin_as_library, private_no_mangle_fns, private_no_mangle_statics, 28 | raw_pointer_derive, stable_features, unconditional_recursion, unknown_lints, // unsafe_code, 29 | unsigned_negation, unused, unused_allocation, unused_attributes, unused_comparisons, 30 | unused_features, unused_parens, while_true)] 31 | 32 | #![warn(trivial_casts, trivial_numeric_casts, unused_extern_crates, unused_import_braces, 33 | unused_qualifications, variant_size_differences)] 34 | 35 | //! #Safe Network Data Types 36 | //! 37 | //! This library implements the fundimental data types used on the SAFE Network 38 | //! The serialisation mechnism used is ``cbor``` which is an IETF Rfc [7049](http://tools.ietf.org/html/rfc7049) 39 | //! for serialising data and is an attempt to upgrade messagepack and ASN.1 40 | //! On disk serialisation is [JSON](https://www.ietf.org/rfc/rfc4627.txt) 41 | //! 42 | //! [Project github page](https://github.com/maidsafe/maidsafe_types) 43 | 44 | extern crate rustc_serialize; 45 | extern crate sodiumoxide; 46 | extern crate cbor; 47 | extern crate routing; 48 | 49 | /// Helper provides helper functions for array to vector conversions and vice versa 50 | #[macro_use] 51 | pub mod helper; 52 | /// Holds the structs for Id related Types such as Maid, AnMaid, Mpid, etc 53 | pub mod id; 54 | /// Holds the structs related to data such as ImmutableData/Backup/Sacrificial and StructuredData 55 | pub mod data; 56 | /// SafeCoin related details 57 | pub mod coin; 58 | 59 | pub use id::{RevocationIdType, IdType, PublicIdType}; 60 | pub use data::{ImmutableData, ImmutableDataBackup, ImmutableDataSacrificial, StructuredData}; 61 | 62 | /// TypeTag trait 63 | pub trait TypeTag { 64 | /// returns type tag 65 | fn type_tag(&self) -> u64; 66 | } 67 | 68 | /// Interface to IdTypes 69 | pub trait IdTypeTags { 70 | /// returns tag type for revocation id type 71 | fn revocation_id_type_tag(&self) -> u64; 72 | /// returns tag type for id type 73 | fn id_type_tag(&self) -> u64; 74 | /// returns tag type for public id type 75 | fn public_id_type_tag(&self) -> u64; 76 | } 77 | 78 | /// TypeTags for Maid type variants 79 | pub struct MaidTypeTags; 80 | 81 | /// TypeTags for Maid type variants 82 | pub struct MpidTypeTags; 83 | 84 | impl IdTypeTags for MaidTypeTags { 85 | /// returns tag type for AnMaid type 86 | fn revocation_id_type_tag(&self) -> u64 { data_tags::AN_MAID_TAG } 87 | /// returns tag type for Maid type 88 | fn id_type_tag(&self) -> u64 { data_tags::MAID_TAG } 89 | /// returns tag type for PublicMaid type 90 | fn public_id_type_tag(&self) -> u64 { data_tags::PUBLIC_MAID_TAG } 91 | } 92 | 93 | impl IdTypeTags for MpidTypeTags { 94 | /// returns tag type for AnMpid type 95 | fn revocation_id_type_tag(&self) -> u64 { data_tags::AN_MPID_TAG } 96 | /// returns tag type for Mpid type 97 | fn id_type_tag(&self) -> u64 { data_tags::MPID_TAG } 98 | /// returns tag type for PublicMpid type 99 | fn public_id_type_tag(&self) -> u64 { data_tags::PUBLIC_MPID_TAG } 100 | } 101 | 102 | /// Random trait is used to generate random instances. 103 | /// Used in the test mod 104 | pub trait Random { 105 | /// Generates a random instance and returns the created random instance 106 | fn generate_random() -> Self; 107 | } 108 | /// Crypto Error types 109 | pub enum CryptoError { 110 | /// Unknown Error Type 111 | Unknown 112 | } 113 | 114 | /// All Maidsafe tagging should offset from this 115 | pub const MAIDSAFE_TAG: u64 = 5483_000; 116 | 117 | /// All Maidsafe Data tags 118 | #[allow(missing_docs)] 119 | pub mod data_tags { 120 | pub const MAIDSAFE_DATA_TAG: u64 = ::MAIDSAFE_TAG + 100; 121 | 122 | pub const IMMUTABLE_DATA_TAG: u64 = MAIDSAFE_DATA_TAG + 1; 123 | pub const IMMUTABLE_DATA_BACKUP_TAG: u64 = MAIDSAFE_DATA_TAG + 2; 124 | pub const IMMUTABLE_DATA_SACRIFICIAL_TAG: u64 = MAIDSAFE_DATA_TAG + 3; 125 | pub const STRUCTURED_DATA_TAG: u64 = MAIDSAFE_DATA_TAG + 4; 126 | pub const AN_MPID_TAG: u64 = MAIDSAFE_DATA_TAG + 5; 127 | pub const AN_MAID_TAG: u64 = MAIDSAFE_DATA_TAG + 6; 128 | pub const MAID_TAG: u64 = MAIDSAFE_DATA_TAG + 7; 129 | pub const MPID_TAG: u64 = MAIDSAFE_DATA_TAG + 8; 130 | pub const PUBLIC_MAID_TAG: u64 = MAIDSAFE_DATA_TAG + 9; 131 | pub const PUBLIC_MPID_TAG: u64 = MAIDSAFE_DATA_TAG + 10; 132 | } 133 | 134 | mod test_utils; 135 | -------------------------------------------------------------------------------- /src/test_utils.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 MaidSafe.net limited. 2 | // 3 | // This SAFE Network Software is licensed to you under (1) the MaidSafe.net Commercial License, 4 | // version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which 5 | // licence you accepted on initial access to the Software (the "Licences"). 6 | // 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. 10 | // 11 | // Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed 12 | // under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. 14 | // 15 | // Please review the Licences for the specific language governing permissions and limitations 16 | // relating to use of the SAFE Network Software. 17 | 18 | pub enum Parser { 19 | StructData(::data::StructuredData), 20 | ImmutData(::data::ImmutableData), 21 | ImmutDataBkup(::data::ImmutableDataBackup), 22 | ImmutDataSacrificial(::data::ImmutableDataSacrificial), 23 | Maid(::id::IdType), 24 | Mpid(::id::IdType), 25 | AnMaid(::id::RevocationIdType), 26 | AnMpid(::id::RevocationIdType), 27 | PubMaid(::id::PublicIdType), 28 | PubMpid(::id::PublicIdType), 29 | Unknown(u64), 30 | } 31 | 32 | impl ::rustc_serialize::Decodable for Parser { 33 | fn decode(d: &mut D) -> Result { 34 | let tag = try!(d.read_u64()); 35 | 36 | match tag { 37 | ::data_tags::IMMUTABLE_DATA_TAG => Ok(Parser::ImmutData(try!(::rustc_serialize::Decodable::decode(d)))), 38 | ::data_tags::IMMUTABLE_DATA_BACKUP_TAG => Ok(Parser::ImmutDataBkup(try!(::rustc_serialize::Decodable::decode(d)))), 39 | ::data_tags::IMMUTABLE_DATA_SACRIFICIAL_TAG => Ok(Parser::ImmutDataSacrificial(try!(::rustc_serialize::Decodable::decode(d)))), 40 | ::data_tags::STRUCTURED_DATA_TAG => Ok(Parser::StructData(try!(::rustc_serialize::Decodable::decode(d)))), 41 | ::data_tags::MAID_TAG => Ok(Parser::Maid(try!(::rustc_serialize::Decodable::decode(d)))), 42 | ::data_tags::MPID_TAG => Ok(Parser::Mpid(try!(::rustc_serialize::Decodable::decode(d)))), 43 | ::data_tags::AN_MAID_TAG => Ok(Parser::AnMaid(try!(::rustc_serialize::Decodable::decode(d)))), 44 | ::data_tags::AN_MPID_TAG => Ok(Parser::AnMpid(try!(::rustc_serialize::Decodable::decode(d)))), 45 | ::data_tags::PUBLIC_MAID_TAG => Ok(Parser::PubMaid(try!(::rustc_serialize::Decodable::decode(d)))), 46 | ::data_tags::PUBLIC_MPID_TAG => Ok(Parser::PubMpid(try!(::rustc_serialize::Decodable::decode(d)))), 47 | _ => Ok(Parser::Unknown(tag)), 48 | } 49 | } 50 | } 51 | 52 | --------------------------------------------------------------------------------