Refactoring to allow for a more flexible API.

This commit is contained in:
Frederic Jacobs
2016-12-02 14:56:12 +01:00
committed by GitHub
parent aeb8e4c21f
commit f5ab309dd6
60 changed files with 6460 additions and 486 deletions

61
Cargo.lock generated
View File

@ -2,16 +2,51 @@
name = "rusty_secrets"
version = "0.0.3"
dependencies = [
"merkle_sigs 0.1.0 (git+https://github.com/SpinResearch/merkle_sigs.rs)",
"protobuf 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"ring 0.6.0-alpha (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.21 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "lamport_sigs"
version = "0.1.1"
source = "git+https://github.com/SpinResearch/lamport.rs#4ddf030e1514383d13dc86b75c4c239a4935dc48"
dependencies = [
"rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"ring 0.6.0-alpha (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "lazy_static"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libc"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "merkle"
version = "0.1.0"
source = "git+https://github.com/SpinResearch/merkle.rs#450325872473884e73790ebd6cf50fa9ce0b8aa8"
dependencies = [
"protobuf 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)",
"ring 0.6.0-alpha (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "merkle_sigs"
version = "0.1.0"
source = "git+https://github.com/SpinResearch/merkle_sigs.rs#ae2e85ab6d694eaed4c5488964af64ffce7bd0f7"
dependencies = [
"lamport_sigs 0.1.1 (git+https://github.com/SpinResearch/lamport.rs)",
"merkle 0.1.0 (git+https://github.com/SpinResearch/merkle.rs)",
"ring 0.6.0-alpha (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "protobuf"
version = "1.0.24"
@ -19,19 +54,39 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rand"
version = "0.3.14"
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "ring"
version = "0.6.0-alpha"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"untrusted 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rustc-serialize"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "untrusted"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum lamport_sigs 0.1.1 (git+https://github.com/SpinResearch/lamport.rs)" = "<none>"
"checksum lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6abe0ee2e758cd6bc8a2cd56726359007748fbf4128da998b65d0b70f881e19b"
"checksum libc 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)" = "044d1360593a78f5c8e5e710beccdc24ab71d1f01bc19a29bcacdba22e8475d8"
"checksum merkle 0.1.0 (git+https://github.com/SpinResearch/merkle.rs)" = "<none>"
"checksum merkle_sigs 0.1.0 (git+https://github.com/SpinResearch/merkle_sigs.rs)" = "<none>"
"checksum protobuf 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)" = "6ec4c2fe04370298218a09ab53a534febf54c160c5554e4de987b6d73c916d5d"
"checksum rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "2791d88c6defac799c3f20d74f094ca33b9332612d9aef9078519c82e4fe04a5"
"checksum rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "022e0636ec2519ddae48154b028864bdce4eaf7d35226ab8e65c611be97b189d"
"checksum ring 0.6.0-alpha (registry+https://github.com/rust-lang/crates.io-index)" = "756e9bcca47cd772b23f9958ea0952a18a5a3e294e4ab3b7d019e6c06955f191"
"checksum rustc-serialize 0.3.21 (registry+https://github.com/rust-lang/crates.io-index)" = "bff9fc1c79f2dec76b253273d07682e94a978bd8f132ded071188122b2af9818"
"checksum untrusted 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "193df64312e3515fd983ded55ad5bcaa7647a035804828ed757e832ce6029ef3"

View File

@ -11,4 +11,7 @@ build = "build.rs"
[dependencies]
rustc-serialize = "^0.3.18"
rand = "^0.3.14"
ring = "0.6.0-alpha"
merkle_sigs = { git = "https://github.com/SpinResearch/merkle_sigs.rs" }
[dependencies.protobuf]

4
Makefile Normal file
View File

@ -0,0 +1,4 @@
doc:
rm -rf docs/
cargo doc --no-deps
mv target/doc docs/

View File

@ -47,9 +47,7 @@ A share is built out of three parts separated with a dash: K-N-D.
- K specifies the number of shares necessary to recover the secret.
- N is the identifier of the share and varies between 1 and n where n is the total number of generated shares.
- The D part is a Base64 encoding of a specific share's raw data.
// TODO: Rewrite documentation to match current implementation
- The D part is a Base64 encoding of a `ShareData` protobuf.
## Vocabulary

0
docs/.lock Executable file
View File

64
docs/COPYRIGHT.txt Normal file
View File

@ -0,0 +1,64 @@
These documentation pages include resources by third parties. This copyright
file applies only to those resources. The following third party resources are
included, and carry their own copyright notices and license terms:
* Fira Sans (FiraSans-Regular.woff, FiraSans-Medium.woff):
Copyright (c) 2014, Mozilla Foundation https://mozilla.org/
with Reserved Font Name Fira Sans.
Copyright (c) 2014, Telefonica S.A.
Licensed under the SIL Open Font License, Version 1.1.
See FiraSans-LICENSE.txt.
* Heuristica (Heuristica-Italic.woff):
Copyright 1989, 1991 Adobe Systems Incorporated. All rights reserved.
Utopia is either a registered trademark or trademark of Adobe Systems
Incorporated in the United States and/or other countries. Used under
license.
Copyright 2006 Han The Thanh, Vntopia font family, http://vntex.sf.net
Copyright (c) 2008-2012, Andrey V. Panov (panov@canopus.iacp.dvo.ru),
with Reserved Font Name Heuristica.
Licensed under the SIL Open Font License, Version 1.1.
See Heuristica-LICENSE.txt.
* jQuery (jquery-2.1.4.min.js):
Copyright 2005, 2015 jQuery Foundation, Inc.
Licensed under the MIT license (see LICENSE-MIT.txt).
* rustdoc.css, main.js, and playpen.js:
Copyright 2015 The Rust Developers.
Licensed under the Apache License, Version 2.0 (see LICENSE-APACHE.txt) or
the MIT license (LICENSE-MIT.txt) at your option.
* normalize.css:
Copyright (c) Nicolas Gallagher and Jonathan Neal.
Licensed under the MIT license (see LICENSE-MIT.txt).
* Source Code Pro (SourceCodePro-Regular.woff, SourceCodePro-Semibold.woff):
Copyright 2010, 2012 Adobe Systems Incorporated (http://www.adobe.com/),
with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark
of Adobe Systems Incorporated in the United States and/or other countries.
Licensed under the SIL Open Font License, Version 1.1.
See SourceCodePro-LICENSE.txt.
* Source Serif Pro (SourceSerifPro-Regular.woff, SourceSerifPro-Bold.woff):
Copyright 2014 Adobe Systems Incorporated (http://www.adobe.com/), with
Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of
Adobe Systems Incorporated in the United States and/or other countries.
Licensed under the SIL Open Font License, Version 1.1.
See SourceSerifPro-LICENSE.txt.
This copyright file is intended to be distributed with rustdoc output.

99
docs/FiraSans-LICENSE.txt Normal file
View File

@ -0,0 +1,99 @@
Copyright (c) 2014, Mozilla Foundation https://mozilla.org/
with Reserved Font Name Fira Sans.
Copyright (c) 2014, Mozilla Foundation https://mozilla.org/
with Reserved Font Name Fira Mono.
Copyright (c) 2014, Telefonica S.A.
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.

BIN
docs/FiraSans-Medium.woff Normal file

Binary file not shown.

BIN
docs/FiraSans-Regular.woff Normal file

Binary file not shown.

BIN
docs/Heuristica-Italic.woff Normal file

Binary file not shown.

101
docs/Heuristica-LICENSE.txt Normal file
View File

@ -0,0 +1,101 @@
Copyright 1989, 1991 Adobe Systems Incorporated. All rights reserved.
Utopia is either a registered trademark or trademark of Adobe Systems
Incorporated in the United States and/or other countries. Used under
license.
Copyright 2006 Han The Thanh, Vntopia font family, http://vntex.sf.net
Copyright (c) 2008-2012, Andrey V. Panov (panov@canopus.iacp.dvo.ru),
with Reserved Font Name Heuristica.
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.

201
docs/LICENSE-APACHE.txt Normal file
View File

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

23
docs/LICENSE-MIT.txt Normal file
View File

@ -0,0 +1,23 @@
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

View File

@ -0,0 +1,93 @@
Copyright 2010, 2012 Adobe Systems Incorporated (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe Systems Incorporated in the United States and/or other countries.
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,93 @@
Copyright 2014 Adobe Systems Incorporated (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe Systems Incorporated in the United States and/or other countries.
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.

Binary file not shown.

View File

@ -0,0 +1,10 @@
(function() {var implementors = {};
implementors["rusty_secrets"] = ["impl <a class='trait' href='https://doc.rust-lang.org/nightly/core/convert/trait.From.html' title='core::convert::From'>From</a>&lt;Error&gt; for <a class='struct' href='https://doc.rust-lang.org/nightly/std/io/error/struct.Error.html' title='std::io::error::Error'>Error</a>",];
if (window.register_implementors) {
window.register_implementors(implementors);
} else {
window.pending_implementors = implementors;
}
})()

4
docs/jquery.js vendored Normal file

File diff suppressed because one or more lines are too long

133
docs/main.css Normal file
View File

@ -0,0 +1,133 @@
/**
* Copyright 2015 The Rust Project Developers. See the COPYRIGHT
* file at the top-level directory of this distribution and at
* http://rust-lang.org/COPYRIGHT.
*
* Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
* http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
* <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
* option. This file may not be copied, modified, or distributed
* except according to those terms.
*/
/* General structure and fonts */
body {
background-color: white;
color: black;
}
h1, h2, h3:not(.impl):not(.method):not(.type):not(.tymethod), h4:not(.method):not(.type):not(.tymethod) {
color: black;
}
h1.fqn {
border-bottom-color: #D5D5D5;
}
h2, h3:not(.impl):not(.method):not(.type):not(.tymethod), h4:not(.method):not(.type):not(.tymethod) {
border-bottom-color: #DDDDDD;
}
.in-band {
background-color: white;
}
div.stability > em > code {
background-color: initial;
}
.docblock code, .docblock-short code {
background-color: #F5F5F5;
}
pre {
background-color: #F5F5F5;
}
.sidebar .location {
background: #e1e1e1;
color: #333;
}
.block a:hover {
background: #F5F5F5;
}
.line-numbers span { color: #c67e2d; }
.line-numbers .line-highlighted {
background-color: #f6fdb0 !important;
}
:target { background: #FDFFD3; }
.content .highlighted {
color: #000 !important;
background-color: #ccc;
}
.content .highlighted a, .content .highlighted span { color: #000 !important; }
.content .highlighted.trait { background-color: #fece7e; }
.content .highlighted.mod { background-color: #afc6e4; }
.content .highlighted.enum { background-color: #b4d1b9; }
.content .highlighted.struct { background-color: #e7b1a0; }
.content .highlighted.fn { background-color: #c6afb3; }
.content .highlighted.method { background-color: #c6afb3; }
.content .highlighted.tymethod { background-color: #c6afb3; }
.content .highlighted.type { background-color: #c6afb3; }
.docblock h1, .docblock h2, .docblock h3, .docblock h4, .docblock h5 {
border-bottom-color: #DDD;
}
.docblock table {
border-color: #ddd;
}
.docblock table td {
border-top-color: #ddd;
border-bottom-color: #ddd;
}
.docblock table th {
border-top-color: #ddd;
border-bottom-color: #ddd;
}
.content span.primitive, .content a.primitive, .block a.current.primitive { color: #39a7bf; }
.content span.externcrate,
.content span.mod, .content a.mod, .block a.current.mod { color: #4d76ae; }
.content span.fn, .content a.fn, .block a.current.fn,
.content span.method, .content a.method, .block a.current.method,
.content span.tymethod, .content a.tymethod, .block a.current.tymethod,
.content .fnname { color: #8c6067; }
pre.rust .comment { color: #8E908C; }
pre.rust .doccomment { color: #4D4D4C; }
nav {
border-bottom-color: #e0e0e0;
}
nav.main .current {
border-top-color: #000;
border-bottom-color: #000;
}
nav.main .separator {
border: 1px solid #000;
}
a {
color: #000;
}
.docblock a, .docblock-short a, .stability a {
color: #3873AD;
}
a.test-arrow {
color: #f5f5f5;
}
.content span.trait, .content a.trait, .block a.current.trait { color: #7c5af3; }
.search-input {
color: #555;
box-shadow: 0 0 0 1px #e0e0e0, 0 0 0 2px transparent;
background-color: white;
}
em.stab.unstable { background: #FFF5D6; border-color: #FFC600; }
em.stab.deprecated { background: #F3DFFF; border-color: #7F0087; }

1046
docs/main.js Normal file

File diff suppressed because it is too large Load Diff

1
docs/normalize.css vendored Normal file
View File

@ -0,0 +1 @@
/*! normalize.css v3.0.0 | MIT License | git.io/normalize */html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}body{margin:0}article,aside,details,figcaption,figure,footer,header,hgroup,main,nav,section,summary{display:block}audio,canvas,progress,video{display:inline-block;vertical-align:baseline}audio:not([controls]){display:none;height:0}[hidden],template{display:none}a{background:transparent}a:active,a:hover{outline:0}abbr[title]{border-bottom:1px dotted}b,strong{font-weight:bold}dfn{font-style:italic}h1{font-size:2em;margin:.67em 0}mark{background:#ff0;color:#000}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sup{top:-0.5em}sub{bottom:-0.25em}img{border:0}svg:not(:root){overflow:hidden}figure{margin:1em 40px}hr{-moz-box-sizing:content-box;box-sizing:content-box;height:0}pre{overflow:auto}code,kbd,pre,samp{font-family:monospace,monospace;font-size:1em}button,input,optgroup,select,textarea{color:inherit;font:inherit;margin:0}button{overflow:visible}button,select{text-transform:none}button,html input[type="button"],input[type="reset"],input[type="submit"]{-webkit-appearance:button;cursor:pointer}button[disabled],html input[disabled]{cursor:default}button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}input{line-height:normal}input[type="checkbox"],input[type="radio"]{box-sizing:border-box;padding:0}input[type="number"]::-webkit-inner-spin-button,input[type="number"]::-webkit-outer-spin-button{height:auto}input[type="search"]{-webkit-appearance:textfield;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box}input[type="search"]::-webkit-search-cancel-button,input[type="search"]::-webkit-search-decoration{-webkit-appearance:none}fieldset{border:1px solid silver;margin:0 2px;padding:.35em .625em .75em}legend{border:0;padding:0}textarea{overflow:auto}optgroup{font-weight:bold}table{border-collapse:collapse;border-spacing:0}td,th{padding:0}

43
docs/playpen.js Normal file
View File

@ -0,0 +1,43 @@
// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
/*jslint browser: true, es5: true */
/*globals $: true, rootPath: true */
document.addEventListener('DOMContentLoaded', function() {
'use strict';
if (!window.playgroundUrl) {
return;
}
var featureRegexp = new RegExp('^\s*#!\\[feature\\(\.*?\\)\\]');
var elements = document.querySelectorAll('pre.rust-example-rendered');
Array.prototype.forEach.call(elements, function(el) {
el.onmouseover = function(e) {
if (el.contains(e.relatedTarget)) {
return;
}
var a = el.querySelectorAll('a.test-arrow')[0];
var code = el.previousElementSibling.textContent;
var channel = '';
if (featureRegexp.test(code)) {
channel = '&version=nightly';
}
a.setAttribute('href', window.playgroundUrl + '?code=' +
encodeURIComponent(code) + channel);
};
});
});

751
docs/rustdoc.css Normal file
View File

@ -0,0 +1,751 @@
@import "normalize.css";
/**
* Copyright 2013 The Rust Project Developers. See the COPYRIGHT
* file at the top-level directory of this distribution and at
* http://rust-lang.org/COPYRIGHT.
*
* Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
* http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
* <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
* option. This file may not be copied, modified, or distributed
* except according to those terms.
*/
/* See FiraSans-LICENSE.txt for the Fira Sans license. */
@font-face {
font-family: 'Fira Sans';
font-style: normal;
font-weight: 400;
src: local('Fira Sans'), url("FiraSans-Regular.woff") format('woff');
}
@font-face {
font-family: 'Fira Sans';
font-style: normal;
font-weight: 500;
src: local('Fira Sans Medium'), url("FiraSans-Medium.woff") format('woff');
}
/* See SourceSerifPro-LICENSE.txt for the Source Serif Pro license and
* Heuristica-LICENSE.txt for the Heuristica license. */
@font-face {
font-family: 'Source Serif Pro';
font-style: normal;
font-weight: 400;
src: local('Source Serif Pro'), url("SourceSerifPro-Regular.woff") format('woff');
}
@font-face {
font-family: 'Source Serif Pro';
font-style: italic;
font-weight: 400;
src: url("Heuristica-Italic.woff") format('woff');
}
@font-face {
font-family: 'Source Serif Pro';
font-style: normal;
font-weight: 700;
src: local('Source Serif Pro Bold'), url("SourceSerifPro-Bold.woff") format('woff');
}
/* See SourceCodePro-LICENSE.txt for the Source Code Pro license. */
@font-face {
font-family: 'Source Code Pro';
font-style: normal;
font-weight: 400;
src: local('Source Code Pro'), url("SourceCodePro-Regular.woff") format('woff');
}
@font-face {
font-family: 'Source Code Pro';
font-style: normal;
font-weight: 600;
src: local('Source Code Pro Semibold'), url("SourceCodePro-Semibold.woff") format('woff');
}
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
/* General structure and fonts */
body {
font: 16px/1.4 "Source Serif Pro", Georgia, Times, "Times New Roman", serif;
margin: 0;
position: relative;
padding: 10px 15px 20px 15px;
-webkit-font-feature-settings: "kern", "liga";
-moz-font-feature-settings: "kern", "liga";
font-feature-settings: "kern", "liga";
}
h1 {
font-size: 1.5em;
}
h2 {
font-size: 1.4em;
}
h3 {
font-size: 1.3em;
}
h1, h2, h3:not(.impl):not(.method):not(.type):not(.tymethod), h4:not(.method):not(.type):not(.tymethod) {
font-weight: 500;
margin: 20px 0 15px 0;
padding-bottom: 6px;
}
h1.fqn {
border-bottom: 1px dashed;
margin-top: 0;
position: relative;
}
h2, h3:not(.impl):not(.method):not(.type):not(.tymethod), h4:not(.method):not(.type):not(.tymethod) {
border-bottom: 1px solid;
}
h3.impl, h3.method, h4.method, h3.type, h4.type {
font-weight: 600;
margin-top: 10px;
margin-bottom: 10px;
position: relative;
}
h3.impl, h3.method, h3.type {
margin-top: 15px;
}
h1, h2, h3, h4, .sidebar, a.source, .search-input, .content table :not(code)>a, .collapse-toggle {
font-family: "Fira Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
}
ol, ul {
padding-left: 25px;
}
ul ul, ol ul, ul ol, ol ol {
margin-bottom: 0;
}
p {
margin: 0 0 .6em 0;
}
code, pre {
font-family: "Source Code Pro", Menlo, Monaco, Consolas, "DejaVu Sans Mono", Inconsolata, monospace;
white-space: pre-wrap;
}
.docblock code, .docblock-short code {
border-radius: 3px;
padding: 0 0.2em;
}
.docblock pre code, .docblock-short pre code {
padding: 0;
}
pre {
padding: 14px;
}
.source pre {
padding: 20px;
}
img {
max-width: 100%;
}
.content.source {
margin-top: 50px;
max-width: none;
overflow: visible;
margin-left: 0px;
min-width: 70em;
}
nav.sub {
font-size: 16px;
text-transform: uppercase;
}
.sidebar {
width: 200px;
position: absolute;
left: 0;
top: 0;
min-height: 100%;
}
.content, nav { max-width: 960px; }
/* Everything else */
.js-only, .hidden { display: none !important; }
.sidebar {
padding: 10px;
}
.sidebar img {
margin: 20px auto;
display: block;
}
.sidebar .location {
font-size: 17px;
margin: 30px 0 20px 0;
text-align: center;
}
.location a:first-child { font-weight: 500; }
.block {
padding: 0 10px;
margin-bottom: 14px;
}
.block h2, .block h3 {
margin-top: 0;
margin-bottom: 8px;
text-align: center;
}
.block ul, .block li {
margin: 0;
padding: 0;
list-style: none;
}
.block a {
display: block;
text-overflow: ellipsis;
overflow: hidden;
line-height: 15px;
padding: 7px 5px;
font-size: 14px;
font-weight: 300;
transition: border 500ms ease-out;
}
.content {
padding: 15px 0;
}
.content.source pre.rust {
white-space: pre;
overflow: auto;
padding-left: 0;
}
.content pre.line-numbers {
float: left;
border: none;
position: relative;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.line-numbers span { cursor: pointer; }
.docblock-short p {
display: inline;
}
.docblock-short.nowrap {
display: block;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.docblock-short p {
overflow: hidden;
text-overflow: ellipsis;
margin: 0;
}
.docblock-short code { white-space: nowrap; }
.docblock h1, .docblock h2, .docblock h3, .docblock h4, .docblock h5 {
border-bottom: 1px solid;
}
.docblock h1 { font-size: 1.3em; }
.docblock h2 { font-size: 1.15em; }
.docblock h3, .docblock h4, .docblock h5 { font-size: 1em; }
.docblock {
margin-left: 24px;
}
.content .out-of-band {
font-size: 23px;
margin: 0px;
padding: 0px;
text-align: right;
display: inline-block;
font-weight: normal;
position: absolute;
right: 0;
}
h3.impl > .out-of-band {
font-size: 21px;
}
h4 > code, h3 > code, .invisible > code {
position: inherit;
}
.in-band, code {
z-index: 5;
}
.invisible {
background: rgba(0, 0, 0, 0);
width: 100%;
display: inline-block;
}
.content .in-band {
margin: 0px;
padding: 0px;
display: inline-block;
}
#main { position: relative; }
#main > .since {
top: inherit;
font-family: "Fira Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
}
.content table {
border-spacing: 0 5px;
border-collapse: separate;
}
.content td { vertical-align: top; }
.content td:first-child { padding-right: 20px; }
.content td p:first-child { margin-top: 0; }
.content td h1, .content td h2 { margin-left: 0; font-size: 1.1em; }
.docblock table {
border: 1px solid;
margin: .5em 0;
border-collapse: collapse;
width: 100%;
}
.docblock table td {
padding: .5em;
border-top: 1px dashed;
border-bottom: 1px dashed;
}
.docblock table th {
padding: .5em;
text-align: left;
border-top: 1px solid;
border-bottom: 1px solid;
}
.content .item-list {
list-style-type: none;
padding: 0;
}
.content .item-list li { margin-bottom: 3px; }
.content .multi-column {
-moz-column-count: 5;
-moz-column-gap: 2.5em;
-webkit-column-count: 5;
-webkit-column-gap: 2.5em;
column-count: 5;
column-gap: 2.5em;
}
.content .multi-column li { width: 100%; display: inline-block; }
.content .method {
font-size: 1em;
position: relative;
}
/* Shift "where ..." part of method or fn definition down a line */
.content .method .where, .content .fn .where { display: block; }
/* Bit of whitespace to indent it */
.content .method .where::before, .content .fn .where::before { content: ' '; }
.content .methods > div { margin-left: 40px; }
.content .impl-items .docblock, .content .impl-items .stability {
margin-left: 40px;
}
.content .impl-items .method, .content .impl-items > .type {
margin-left: 20px;
}
.content .stability code {
font-size: 90%;
}
/* Shift where in trait listing down a line */
pre.trait .where::before {
content: '\a ';
}
nav {
border-bottom: 1px solid;
padding-bottom: 10px;
margin-bottom: 10px;
}
nav.main {
padding: 20px 0;
text-align: center;
}
nav.main .current {
border-top: 1px solid;
border-bottom: 1px solid;
}
nav.main .separator {
border: 1px solid;
display: inline-block;
height: 23px;
margin: 0 20px;
}
nav.sum { text-align: right; }
nav.sub form { display: inline; }
nav.sub, .content {
margin-left: 230px;
}
a {
text-decoration: none;
background: transparent;
}
.docblock a:hover, .docblock-short a:hover, .stability a {
text-decoration: underline;
}
.content span.enum, .content a.enum, .block a.current.enum { color: #5e9766; }
.content span.struct, .content a.struct, .block a.current.struct { color: #df3600; }
.content span.type, .content a.type, .block a.current.type { color: #e57300; }
.content span.macro, .content a.macro, .block a.current.macro { color: #068000; }
.block a.current.crate { font-weight: 500; }
.search-input {
width: 100%;
/* Override Normalize.css: we have margins and do
not want to overflow - the `moz` attribute is necessary
until Firefox 29, too early to drop at this point */
-moz-box-sizing: border-box !important;
box-sizing: border-box !important;
outline: none;
border: none;
border-radius: 1px;
margin-top: 5px;
padding: 10px 16px;
font-size: 17px;
transition: border-color 300ms ease;
transition: border-radius 300ms ease-in-out;
transition: box-shadow 300ms ease-in-out;
}
.search-input:focus {
border-color: #66afe9;
border-radius: 2px;
border: 0;
outline: 0;
box-shadow: 0 0 8px #078dd8;
}
.search-results .desc {
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
display: block;
}
.search-results a {
display: block;
}
.content .search-results td:first-child { padding-right: 0; }
.content .search-results td:first-child a { padding-right: 10px; }
tr.result span.primitive::after { content: ' (primitive type)'; font-style: italic; color: black;
}
body.blur > :not(#help) {
filter: blur(8px);
-webkit-filter: blur(8px);
opacity: .7;
}
#help {
width: 100%;
height: 100vh;
position: fixed;
top: 0;
left: 0;
display: flex;
justify-content: center;
align-items: center;
}
#help > div {
flex: 0 0 auto;
background: #e9e9e9;
box-shadow: 0 0 6px rgba(0,0,0,.2);
width: 550px;
height: 330px;
border: 1px solid #bfbfbf;
}
#help dt {
float: left;
border-radius: 4px;
border: 1px solid #bfbfbf;
background: #fff;
width: 23px;
text-align: center;
clear: left;
display: block;
margin-top: -1px;
}
#help dd { margin: 5px 33px; }
#help .infos { padding-left: 0; }
#help h1, #help h2 { margin-top: 0; }
#help > div div {
width: 50%;
float: left;
padding: 20px;
}
em.stab {
display: inline-block;
border-width: 1px;
border-style: solid;
padding: 3px;
margin-bottom: 5px;
font-size: 90%;
font-style: normal;
}
em.stab p {
display: inline;
}
.module-item .stab {
border-width: 0;
padding: 0;
margin: 0;
background: inherit !important;
}
.module-item.unstable {
opacity: 0.65;
}
.since {
font-weight: normal;
font-size: initial;
color: grey;
position: absolute;
right: 0;
top: 0;
}
.variants_table {
width: 100%;
}
.variants_table tbody tr td:first-child {
width: 1%; /* make the variant name as small as possible */
}
td.summary-column {
width: 100%;
}
.summary {
padding-right: 0px;
}
.line-numbers :target { background-color: transparent; }
/* Code highlighting */
pre.rust .kw { color: #8959A8; }
pre.rust .kw-2, pre.rust .prelude-ty { color: #4271AE; }
pre.rust .number, pre.rust .string { color: #718C00; }
pre.rust .self, pre.rust .bool-val, pre.rust .prelude-val,
pre.rust .attribute, pre.rust .attribute .ident { color: #C82829; }
pre.rust .macro, pre.rust .macro-nonterminal { color: #3E999F; }
pre.rust .lifetime { color: #B76514; }
.rusttest { display: none; }
pre.rust { position: relative; }
a.test-arrow {
background-color: rgba(78, 139, 202, 0.2);
display: inline-block;
position: absolute;
padding: 5px 10px 5px 10px;
border-radius: 5px;
font-size: 130%;
top: 5px;
right: 5px;
}
a.test-arrow:hover{
background-color: #4e8bca;
}
.section-header:hover a:after {
content: '\2002\00a7\2002';
}
.section-header:hover a {
text-decoration: none;
}
.section-header a {
color: inherit;
}
.collapse-toggle {
font-weight: 300;
position: absolute;
left: -23px;
color: #999;
top: 0;
}
.toggle-wrapper > .collapse-toggle {
left: -24px;
margin-top: 0px;
}
.toggle-wrapper {
position: relative;
}
.toggle-wrapper.collapsed {
height: 1em;
transition: height .2s;
}
.collapse-toggle > .inner {
display: inline-block;
width: 1.2ch;
text-align: center;
}
.toggle-label {
color: #999;
}
.ghost {
display: none;
}
.ghost + .since {
position: initial;
display: table-cell;
}
.since + .srclink {
display: table-cell;
padding-left: 10px;
}
span.since {
position: initial;
font-size: 20px;
margin-right: 5px;
}
.toggle-wrapper > .collapse-toggle {
left: 0;
}
.variant + .toggle-wrapper > a {
margin-top: 5px;
}
.enum > .toggle-wrapper + .docblock, .struct > .toggle-wrapper + .docblock {
margin-left: 30px;
margin-bottom: 20px;
margin-top: 5px;
}
.enum > .collapsed, .struct > .collapsed {
margin-bottom: 25px;
}
.enum .variant, .struct .structfield {
display: block;
}
:target > code {
background: #FDFFD3;
opacity: 1;
}
/* Media Queries */
@media (max-width: 700px) {
body {
padding-top: 0px;
}
.sidebar {
height: 40px;
min-height: 40px;
width: 100%;
margin: 0px;
padding: 0px;
position: static;
}
.sidebar .location {
float: right;
margin: 0px;
padding: 3px 10px 1px 10px;
min-height: 39px;
background: inherit;
text-align: left;
font-size: 24px;
}
.sidebar .location:empty {
padding: 0;
}
.sidebar img {
width: 35px;
margin-top: 5px;
margin-bottom: 0px;
float: left;
}
nav.sub {
margin: 0 auto;
}
.sidebar .block {
display: none;
}
.content {
margin-left: 0px;
}
.content .in-band {
width: 100%;
}
.content .out-of-band {
display: none;
}
.toggle-wrapper > .collapse-toggle {
left: 0px;
}
.toggle-wrapper {
height: 1.5em;
}
}
@media print {
nav.sub, .content .out-of-band, .collapse-toggle {
display: none;
}
}

View File

@ -0,0 +1,128 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="rustdoc">
<meta name="description" content="API documentation for the Rust `generate_shares` fn in crate `rusty_secrets`.">
<meta name="keywords" content="rust, rustlang, rust-lang, generate_shares">
<title>rusty_secrets::generate_shares - Rust</title>
<link rel="stylesheet" type="text/css" href="../rustdoc.css">
<link rel="stylesheet" type="text/css" href="../main.css">
</head>
<body class="rustdoc">
<!--[if lte IE 8]>
<div class="warning">
This old browser is unsupported and will most likely display funky
things.
</div>
<![endif]-->
<nav class="sidebar">
<p class='location'><a href='index.html'>rusty_secrets</a></p><script>window.sidebarCurrent = {name: 'generate_shares', ty: 'fn', relpath: ''};</script><script defer src="sidebar-items.js"></script>
</nav>
<nav class="sub">
<form class="search-form js-only">
<div class="search-container">
<input class="search-input" name="search"
autocomplete="off"
placeholder="Click or press S to search, ? for more options…"
type="search">
</div>
</form>
</nav>
<section id='main' class="content fn">
<h1 class='fqn'><span class='in-band'>Function <a href='index.html'>rusty_secrets</a>::<wbr><a class='fn' href=''>generate_shares</a></span><span class='out-of-band'><span id='render-detail'>
<a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
[<span class='inner'>&#x2212;</span>]
</a>
</span><a id='src-370' class='srclink' href='../src/rusty_secrets/src/sss.rs.html#32-67' title='goto source code'>[src]</a></span></h1>
<pre class='rust fn'>pub fn generate_shares(k: <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.u8.html'>u8</a>, n: <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.u8.html'>u8</a>, secret: <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.slice.html'>&amp;[</a><a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.u8.html'>u8</a><a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.slice.html'>]</a>, sign_shares: <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.bool.html'>bool</a>) -&gt; <a class='type' href='https://doc.rust-lang.org/nightly/std/io/error/type.Result.html' title='std::io::error::Result'>Result</a>&lt;<a class='struct' href='https://doc.rust-lang.org/nightly/collections/vec/struct.Vec.html' title='collections::vec::Vec'>Vec</a>&lt;<a class='struct' href='https://doc.rust-lang.org/nightly/collections/string/struct.String.html' title='collections::string::String'>String</a>&gt;&gt;</pre><div class='docblock'><p>Performs threshold k-out-of-n Shamir secret sharing.</p>
<h1 id='examples' class='section-header'><a href='#examples'>Examples</a></h1>
<pre class='rust rust-example-rendered'>
<span class='kw'>use</span> <span class='ident'>rusty_secrets</span>::<span class='ident'>generate_shares</span>;
<span class='kw'>let</span> <span class='ident'>secret</span> <span class='op'>=</span> <span class='string'>&quot;These programs were never about terrorism: theyre about economic spying,
social control, and diplomatic manipulation. Theyre about power.&quot;</span>.<span class='ident'>to_string</span>();
<span class='kw'>match</span> <span class='ident'>generate_shares</span>(<span class='number'>7</span>, <span class='number'>10</span>, <span class='kw-2'>&amp;</span><span class='ident'>secret</span>.<span class='ident'>into_bytes</span>(), <span class='bool-val'>true</span>){
<span class='prelude-val'>Ok</span>(<span class='ident'>shares</span>) <span class='op'>=&gt;</span> {
<span class='comment'>// Do something with the shares</span>
},
<span class='prelude-val'>Err</span>(_) <span class='op'>=&gt;</span> {}<span class='comment'>// Deal with error}</span>
}<a class='test-arrow' target='_blank' href=''>Run</a></pre>
</div></section>
<section id='search' class="content hidden"></section>
<section class="footer"></section>
<aside id="help" class="hidden">
<div>
<h1 class="hidden">Help</h1>
<div class="shortcuts">
<h2>Keyboard Shortcuts</h2>
<dl>
<dt>?</dt>
<dd>Show this help dialog</dd>
<dt>S</dt>
<dd>Focus the search field</dd>
<dt>&larrb;</dt>
<dd>Move up in search results</dd>
<dt>&rarrb;</dt>
<dd>Move down in search results</dd>
<dt>&#9166;</dt>
<dd>Go to active search result</dd>
<dt>+</dt>
<dd>Collapse/expand all sections</dd>
</dl>
</div>
<div class="infos">
<h2>Search Tricks</h2>
<p>
Prefix searches with a type followed by a colon (e.g.
<code>fn:</code>) to restrict the search to a given type.
</p>
<p>
Accepted types are: <code>fn</code>, <code>mod</code>,
<code>struct</code>, <code>enum</code>,
<code>trait</code>, <code>type</code>, <code>macro</code>,
and <code>const</code>.
</p>
<p>
Search functions by type signature (e.g.
<code>vec -> usize</code> or <code>* -> vec</code>)
</p>
</div>
</div>
</aside>
<script>
window.rootPath = "../";
window.currentCrate = "rusty_secrets";
window.playgroundUrl = "";
</script>
<script src="../jquery.js"></script>
<script src="../main.js"></script>
<script defer src="../search-index.js"></script>
</body>
</html>

View File

@ -0,0 +1,133 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="rustdoc">
<meta name="description" content="API documentation for the Rust `recover_secret` fn in crate `rusty_secrets`.">
<meta name="keywords" content="rust, rustlang, rust-lang, recover_secret">
<title>rusty_secrets::recover_secret - Rust</title>
<link rel="stylesheet" type="text/css" href="../rustdoc.css">
<link rel="stylesheet" type="text/css" href="../main.css">
</head>
<body class="rustdoc">
<!--[if lte IE 8]>
<div class="warning">
This old browser is unsupported and will most likely display funky
things.
</div>
<![endif]-->
<nav class="sidebar">
<p class='location'><a href='index.html'>rusty_secrets</a></p><script>window.sidebarCurrent = {name: 'recover_secret', ty: 'fn', relpath: ''};</script><script defer src="sidebar-items.js"></script>
</nav>
<nav class="sub">
<form class="search-form js-only">
<div class="search-container">
<input class="search-input" name="search"
autocomplete="off"
placeholder="Click or press S to search, ? for more options…"
type="search">
</div>
</form>
</nav>
<section id='main' class="content fn">
<h1 class='fqn'><span class='in-band'>Function <a href='index.html'>rusty_secrets</a>::<wbr><a class='fn' href=''>recover_secret</a></span><span class='out-of-band'><span id='render-detail'>
<a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
[<span class='inner'>&#x2212;</span>]
</a>
</span><a id='src-406' class='srclink' href='../src/rusty_secrets/src/sss.rs.html#111-126' title='goto source code'>[src]</a></span></h1>
<pre class='rust fn'>pub fn recover_secret(shares: <a class='struct' href='https://doc.rust-lang.org/nightly/collections/vec/struct.Vec.html' title='collections::vec::Vec'>Vec</a>&lt;<a class='struct' href='https://doc.rust-lang.org/nightly/collections/string/struct.String.html' title='collections::string::String'>String</a>&gt;, verify_signatures: <a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.bool.html'>bool</a>) -&gt; <a class='type' href='https://doc.rust-lang.org/nightly/std/io/error/type.Result.html' title='std::io::error::Result'>Result</a>&lt;<a class='struct' href='https://doc.rust-lang.org/nightly/collections/vec/struct.Vec.html' title='collections::vec::Vec'>Vec</a>&lt;<a class='primitive' href='https://doc.rust-lang.org/nightly/std/primitive.u8.html'>u8</a>&gt;&gt;</pre><div class='docblock'><p>Recovers the secret from a k-out-of-n Shamir secret sharing.</p>
<p>At least <code>k</code> distinct shares need to be provided to recover the share.</p>
<h1 id='examples' class='section-header'><a href='#examples'>Examples</a></h1>
<pre class='rust rust-example-rendered'>
<span class='kw'>use</span> <span class='ident'>rusty_secrets</span>::<span class='ident'>recover_secret</span>;
<span class='kw'>let</span> <span class='ident'>share1</span> <span class='op'>=</span> <span class='string'>&quot;2-1-Cha7s14Q/mSwWko0ittr+/Uf79RHQMIP&quot;</span>.<span class='ident'>to_string</span>();
<span class='kw'>let</span> <span class='ident'>share2</span> <span class='op'>=</span> <span class='string'>&quot;2-4-ChaydsUJDypD9ZWxwvIICh/cmZvzusOF&quot;</span>.<span class='ident'>to_string</span>();
<span class='kw'>let</span> <span class='ident'>shares</span> <span class='op'>=</span> <span class='macro'>vec</span><span class='macro'>!</span>[<span class='ident'>share1</span>, <span class='ident'>share2</span>];
<span class='kw'>match</span> <span class='ident'>recover_secret</span>(<span class='ident'>shares</span>, <span class='bool-val'>false</span>) {
<span class='prelude-val'>Ok</span>(<span class='ident'>secret</span>) <span class='op'>=&gt;</span> {
<span class='comment'>// Do something with the secret</span>
},
<span class='prelude-val'>Err</span>(<span class='ident'>e</span>) <span class='op'>=&gt;</span> {
<span class='comment'>// Deal with the error</span>
}
}<a class='test-arrow' target='_blank' href=''>Run</a></pre>
</div></section>
<section id='search' class="content hidden"></section>
<section class="footer"></section>
<aside id="help" class="hidden">
<div>
<h1 class="hidden">Help</h1>
<div class="shortcuts">
<h2>Keyboard Shortcuts</h2>
<dl>
<dt>?</dt>
<dd>Show this help dialog</dd>
<dt>S</dt>
<dd>Focus the search field</dd>
<dt>&larrb;</dt>
<dd>Move up in search results</dd>
<dt>&rarrb;</dt>
<dd>Move down in search results</dd>
<dt>&#9166;</dt>
<dd>Go to active search result</dd>
<dt>+</dt>
<dd>Collapse/expand all sections</dd>
</dl>
</div>
<div class="infos">
<h2>Search Tricks</h2>
<p>
Prefix searches with a type followed by a colon (e.g.
<code>fn:</code>) to restrict the search to a given type.
</p>
<p>
Accepted types are: <code>fn</code>, <code>mod</code>,
<code>struct</code>, <code>enum</code>,
<code>trait</code>, <code>type</code>, <code>macro</code>,
and <code>const</code>.
</p>
<p>
Search functions by type signature (e.g.
<code>vec -> usize</code> or <code>* -> vec</code>)
</p>
</div>
</div>
</aside>
<script>
window.rootPath = "../";
window.currentCrate = "rusty_secrets";
window.playgroundUrl = "";
</script>
<script src="../jquery.js"></script>
<script src="../main.js"></script>
<script defer src="../search-index.js"></script>
</body>
</html>

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=fn.generate_shares.html">
</head>
<body>
<p>Redirecting to <a href="fn.generate_shares.html">fn.generate_shares.html</a>...</p>
<script>location.replace("fn.generate_shares.html" + location.search + location.hash);</script>
</body>
</html>

View File

@ -0,0 +1,130 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="rustdoc">
<meta name="description" content="API documentation for the Rust `rusty_secrets` crate.">
<meta name="keywords" content="rust, rustlang, rust-lang, rusty_secrets">
<title>rusty_secrets - Rust</title>
<link rel="stylesheet" type="text/css" href="../rustdoc.css">
<link rel="stylesheet" type="text/css" href="../main.css">
</head>
<body class="rustdoc">
<!--[if lte IE 8]>
<div class="warning">
This old browser is unsupported and will most likely display funky
things.
</div>
<![endif]-->
<nav class="sidebar">
<p class='location'></p><script>window.sidebarCurrent = {name: 'rusty_secrets', ty: 'mod', relpath: '../'};</script>
</nav>
<nav class="sub">
<form class="search-form js-only">
<div class="search-container">
<input class="search-input" name="search"
autocomplete="off"
placeholder="Click or press S to search, ? for more options…"
type="search">
</div>
</form>
</nav>
<section id='main' class="content mod">
<h1 class='fqn'><span class='in-band'>Crate <a class='mod' href=''>rusty_secrets</a></span><span class='out-of-band'><span id='render-detail'>
<a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
[<span class='inner'>&#x2212;</span>]
</a>
</span><a id='src-0' class='srclink' href='../src/rusty_secrets/src/lib.rs.html#1-33' title='goto source code'>[src]</a></span></h1>
<div class='docblock'><p><code>RustySecrets</code> implements Shamir Secret Sharing in Rust. It provides the possibility to sign shares.</p>
</div><h2 id='functions' class='section-header'><a href="#functions">Functions</a></h2>
<table>
<tr class=' module-item'>
<td><a class='fn' href='fn.generate_shares.html'
title='rusty_secrets::generate_shares'>generate_shares</a></td>
<td class='docblock-short'>
<p>Performs threshold k-out-of-n Shamir secret sharing.</p>
</td>
</tr>
<tr class=' module-item'>
<td><a class='fn' href='fn.recover_secret.html'
title='rusty_secrets::recover_secret'>recover_secret</a></td>
<td class='docblock-short'>
<p>Recovers the secret from a k-out-of-n Shamir secret sharing.</p>
</td>
</tr></table></section>
<section id='search' class="content hidden"></section>
<section class="footer"></section>
<aside id="help" class="hidden">
<div>
<h1 class="hidden">Help</h1>
<div class="shortcuts">
<h2>Keyboard Shortcuts</h2>
<dl>
<dt>?</dt>
<dd>Show this help dialog</dd>
<dt>S</dt>
<dd>Focus the search field</dd>
<dt>&larrb;</dt>
<dd>Move up in search results</dd>
<dt>&rarrb;</dt>
<dd>Move down in search results</dd>
<dt>&#9166;</dt>
<dd>Go to active search result</dd>
<dt>+</dt>
<dd>Collapse/expand all sections</dd>
</dl>
</div>
<div class="infos">
<h2>Search Tricks</h2>
<p>
Prefix searches with a type followed by a colon (e.g.
<code>fn:</code>) to restrict the search to a given type.
</p>
<p>
Accepted types are: <code>fn</code>, <code>mod</code>,
<code>struct</code>, <code>enum</code>,
<code>trait</code>, <code>type</code>, <code>macro</code>,
and <code>const</code>.
</p>
<p>
Search functions by type signature (e.g.
<code>vec -> usize</code> or <code>* -> vec</code>)
</p>
</div>
</div>
</aside>
<script>
window.rootPath = "../";
window.currentCrate = "rusty_secrets";
window.playgroundUrl = "";
</script>
<script src="../jquery.js"></script>
<script src="../main.js"></script>
<script defer src="../search-index.js"></script>
</body>
</html>

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=fn.recover_secret.html">
</head>
<body>
<p>Redirecting to <a href="fn.recover_secret.html">fn.recover_secret.html</a>...</p>
<script>location.replace("fn.recover_secret.html" + location.search + location.hash);</script>
</body>
</html>

View File

@ -0,0 +1 @@
initSidebarItems({"fn":[["generate_shares","Performs threshold k-out-of-n Shamir secret sharing."],["recover_secret","Recovers the secret from a k-out-of-n Shamir secret sharing."]]});

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../rusty_secrets/fn.generate_shares.html">
</head>
<body>
<p>Redirecting to <a href="../../rusty_secrets/fn.generate_shares.html">../../rusty_secrets/fn.generate_shares.html</a>...</p>
<script>location.replace("../../rusty_secrets/fn.generate_shares.html" + location.search + location.hash);</script>
</body>
</html>

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../rusty_secrets/fn.recover_secret.html">
</head>
<body>
<p>Redirecting to <a href="../../rusty_secrets/fn.recover_secret.html">../../rusty_secrets/fn.recover_secret.html</a>...</p>
<script>location.replace("../../rusty_secrets/fn.recover_secret.html" + location.search + location.hash);</script>
</body>
</html>

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=fn.generate_shares.html">
</head>
<body>
<p>Redirecting to <a href="fn.generate_shares.html">fn.generate_shares.html</a>...</p>
<script>location.replace("fn.generate_shares.html" + location.search + location.hash);</script>
</body>
</html>

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=fn.recover_secret.html">
</head>
<body>
<p>Redirecting to <a href="fn.recover_secret.html">fn.recover_secret.html</a>...</p>
<script>location.replace("fn.recover_secret.html" + location.search + location.hash);</script>
</body>
</html>

3
docs/search-index.js Normal file
View File

@ -0,0 +1,3 @@
var searchIndex = {};
searchIndex["rusty_secrets"] = {"doc":"`RustySecrets` implements Shamir Secret Sharing in Rust. It provides the possibility to sign shares.","items":[[5,"generate_shares","rusty_secrets","Performs threshold k-out-of-n Shamir secret sharing.",null,null],[5,"recover_secret","","Recovers the secret from a k-out-of-n Shamir secret sharing.",null,{"inputs":[{"name":"vec"},{"name":"bool"}],"output":{"name":"result"}}]],"paths":[]};
initSearch(searchIndex);

View File

@ -0,0 +1,298 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="rustdoc">
<meta name="description" content="Source to the Rust file `src/custom_error.rs`.">
<meta name="keywords" content="rust, rustlang, rust-lang">
<title>custom_error.rs.html -- source</title>
<link rel="stylesheet" type="text/css" href="../../../rustdoc.css">
<link rel="stylesheet" type="text/css" href="../../../main.css">
</head>
<body class="rustdoc">
<!--[if lte IE 8]>
<div class="warning">
This old browser is unsupported and will most likely display funky
things.
</div>
<![endif]-->
<nav class="sidebar">
</nav>
<nav class="sub">
<form class="search-form js-only">
<div class="search-container">
<input class="search-input" name="search"
autocomplete="off"
placeholder="Click or press S to search, ? for more options…"
type="search">
</div>
</form>
</nav>
<section id='main' class="content source"><pre class="line-numbers"><span id="1"> 1</span>
<span id="2"> 2</span>
<span id="3"> 3</span>
<span id="4"> 4</span>
<span id="5"> 5</span>
<span id="6"> 6</span>
<span id="7"> 7</span>
<span id="8"> 8</span>
<span id="9"> 9</span>
<span id="10">10</span>
<span id="11">11</span>
<span id="12">12</span>
<span id="13">13</span>
<span id="14">14</span>
<span id="15">15</span>
<span id="16">16</span>
<span id="17">17</span>
<span id="18">18</span>
<span id="19">19</span>
<span id="20">20</span>
<span id="21">21</span>
<span id="22">22</span>
<span id="23">23</span>
<span id="24">24</span>
<span id="25">25</span>
<span id="26">26</span>
<span id="27">27</span>
<span id="28">28</span>
<span id="29">29</span>
<span id="30">30</span>
<span id="31">31</span>
<span id="32">32</span>
<span id="33">33</span>
<span id="34">34</span>
<span id="35">35</span>
<span id="36">36</span>
<span id="37">37</span>
<span id="38">38</span>
<span id="39">39</span>
<span id="40">40</span>
<span id="41">41</span>
<span id="42">42</span>
<span id="43">43</span>
<span id="44">44</span>
<span id="45">45</span>
<span id="46">46</span>
<span id="47">47</span>
<span id="48">48</span>
<span id="49">49</span>
<span id="50">50</span>
<span id="51">51</span>
<span id="52">52</span>
<span id="53">53</span>
<span id="54">54</span>
<span id="55">55</span>
<span id="56">56</span>
<span id="57">57</span>
<span id="58">58</span>
<span id="59">59</span>
<span id="60">60</span>
<span id="61">61</span>
<span id="62">62</span>
<span id="63">63</span>
<span id="64">64</span>
<span id="65">65</span>
<span id="66">66</span>
<span id="67">67</span>
<span id="68">68</span>
<span id="69">69</span>
<span id="70">70</span>
<span id="71">71</span>
<span id="72">72</span>
<span id="73">73</span>
<span id="74">74</span>
<span id="75">75</span>
<span id="76">76</span>
<span id="77">77</span>
<span id="78">78</span>
<span id="79">79</span>
<span id="80">80</span>
<span id="81">81</span>
<span id="82">82</span>
<span id="83">83</span>
<span id="84">84</span>
<span id="85">85</span>
<span id="86">86</span>
<span id="87">87</span>
<span id="88">88</span>
<span id="89">89</span>
<span id="90">90</span>
<span id="91">91</span>
<span id="92">92</span>
<span id="93">93</span>
<span id="94">94</span>
</pre><pre class='rust '>
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>convert</span>;
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>error</span>;
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>fmt</span>;
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>io</span>;
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>num</span>;
<span class='doccomment'>/// Error struct used for generating an `io::Error` from a generic description.</span>
<span class='attribute'>#[<span class='ident'>derive</span>(<span class='ident'>Debug</span>)]</span>
<span class='kw'>pub</span> <span class='kw'>struct</span> <span class='ident'>Error</span> {
<span class='ident'>descr</span>: <span class='kw-2'>&amp;</span><span class='lifetime'>&#39;static</span> <span class='ident'>str</span>,
<span class='ident'>detail</span>: <span class='prelude-ty'>Option</span><span class='op'>&lt;</span><span class='ident'>String</span><span class='op'>&gt;</span>,
}
<span class='kw'>impl</span> <span class='ident'>Error</span> {
<span class='doccomment'>/// Initializes a new error with a description and optional detail string.</span>
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>new</span>(<span class='ident'>descr</span>: <span class='kw-2'>&amp;</span><span class='lifetime'>&#39;static</span> <span class='ident'>str</span>, <span class='ident'>detail</span>: <span class='prelude-ty'>Option</span><span class='op'>&lt;</span><span class='ident'>String</span><span class='op'>&gt;</span>) <span class='op'>-&gt;</span> <span class='ident'>Error</span> {
<span class='ident'>Error</span> {
<span class='ident'>descr</span>: <span class='ident'>descr</span>,
<span class='ident'>detail</span>: <span class='ident'>detail</span>,
}
}
}
<span class='kw'>impl</span> <span class='ident'>fmt</span>::<span class='ident'>Display</span> <span class='kw'>for</span> <span class='ident'>Error</span> {
<span class='kw'>fn</span> <span class='ident'>fmt</span>(<span class='kw-2'>&amp;</span><span class='self'>self</span>, <span class='ident'>f</span>: <span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> <span class='ident'>fmt</span>::<span class='ident'>Formatter</span>) <span class='op'>-&gt;</span> <span class='ident'>fmt</span>::<span class='prelude-ty'>Result</span> {
<span class='kw'>match</span> <span class='self'>self</span>.<span class='ident'>detail</span> {
<span class='prelude-val'>None</span> <span class='op'>=&gt;</span> <span class='macro'>write</span><span class='macro'>!</span>(<span class='ident'>f</span>, <span class='string'>&quot;{}&quot;</span>, <span class='self'>self</span>.<span class='ident'>descr</span>),
<span class='prelude-val'>Some</span>(<span class='kw-2'>ref</span> <span class='ident'>detail</span>) <span class='op'>=&gt;</span> <span class='macro'>write</span><span class='macro'>!</span>(<span class='ident'>f</span>, <span class='string'>&quot;{} ({})&quot;</span>, <span class='self'>self</span>.<span class='ident'>descr</span>, <span class='ident'>detail</span>),
}
}
}
<span class='kw'>impl</span> <span class='ident'>error</span>::<span class='ident'>Error</span> <span class='kw'>for</span> <span class='ident'>Error</span> {
<span class='kw'>fn</span> <span class='ident'>description</span>(<span class='kw-2'>&amp;</span><span class='self'>self</span>) <span class='op'>-&gt;</span> <span class='kw-2'>&amp;</span><span class='ident'>str</span> {
<span class='self'>self</span>.<span class='ident'>descr</span>
}
<span class='kw'>fn</span> <span class='ident'>cause</span>(<span class='kw-2'>&amp;</span><span class='self'>self</span>) <span class='op'>-&gt;</span> <span class='prelude-ty'>Option</span><span class='op'>&lt;</span><span class='kw-2'>&amp;</span><span class='ident'>error</span>::<span class='ident'>Error</span><span class='op'>&gt;</span> {
<span class='prelude-val'>None</span>
}
}
<span class='kw'>impl</span> <span class='ident'>From</span><span class='op'>&lt;</span><span class='ident'>Error</span><span class='op'>&gt;</span> <span class='kw'>for</span> <span class='ident'>io</span>::<span class='ident'>Error</span> {
<span class='kw'>fn</span> <span class='ident'>from</span>(<span class='ident'>me</span>: <span class='ident'>Error</span>) <span class='op'>-&gt;</span> <span class='ident'>io</span>::<span class='ident'>Error</span> {
<span class='ident'>io</span>::<span class='ident'>Error</span>::<span class='ident'>new</span>(<span class='ident'>io</span>::<span class='ident'>ErrorKind</span>::<span class='ident'>Other</span>, <span class='ident'>me</span>)
}
}
<span class='doccomment'>/// Returns an `io::Error` from description string and optional detail string.</span>
<span class='doccomment'>/// Particularly useful in `Result` expressions.</span>
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>other_io_err</span>(<span class='ident'>descr</span>: <span class='kw-2'>&amp;</span><span class='lifetime'>&#39;static</span> <span class='ident'>str</span>, <span class='ident'>detail</span>: <span class='prelude-ty'>Option</span><span class='op'>&lt;</span><span class='ident'>String</span><span class='op'>&gt;</span>) <span class='op'>-&gt;</span> <span class='ident'>io</span>::<span class='ident'>Error</span> {
<span class='ident'>convert</span>::<span class='ident'>From</span>::<span class='ident'>from</span>(<span class='ident'>Error</span>::<span class='ident'>new</span>(<span class='ident'>descr</span>, <span class='ident'>detail</span>))
}
<span class='doccomment'>/// maps a `ParseIntError` to an `io::Error`</span>
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>pie2io</span>(<span class='ident'>p</span>: <span class='ident'>num</span>::<span class='ident'>ParseIntError</span>) <span class='op'>-&gt;</span> <span class='ident'>io</span>::<span class='ident'>Error</span> {
<span class='ident'>convert</span>::<span class='ident'>From</span>::<span class='ident'>from</span>(<span class='ident'>Error</span>::<span class='ident'>new</span>(<span class='string'>&quot;Integer parsing error&quot;</span>, <span class='prelude-val'>Some</span>(<span class='ident'>p</span>.<span class='ident'>to_string</span>())))
}
<span class='attribute'>#[<span class='ident'>cfg</span>(<span class='ident'>test</span>)]</span>
<span class='kw'>mod</span> <span class='ident'>tests_custom_err</span> {
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>error</span>;
<span class='kw'>use</span> <span class='ident'>custom_error</span>;
<span class='attribute'>#[<span class='ident'>test</span>]</span>
<span class='kw'>fn</span> <span class='ident'>test_custom_error</span>() {
<span class='kw'>let</span> <span class='ident'>desc</span> <span class='op'>=</span> <span class='string'>&quot;Boring error description&quot;</span>;
<span class='kw'>let</span> <span class='ident'>detail</span> <span class='op'>=</span> <span class='string'>&quot;More of it&quot;</span>;
<span class='kw'>let</span> <span class='ident'>ewd</span> <span class='op'>=</span> <span class='ident'>custom_error</span>::<span class='ident'>Error</span>::<span class='ident'>new</span>(<span class='ident'>desc</span>, <span class='prelude-val'>Some</span>(<span class='ident'>detail</span>.<span class='ident'>to_string</span>()));
<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>error</span>::<span class='ident'>Error</span>::<span class='ident'>description</span>(<span class='kw-2'>&amp;</span><span class='ident'>ewd</span>), <span class='ident'>desc</span>);
<span class='kw'>match</span> <span class='ident'>error</span>::<span class='ident'>Error</span>::<span class='ident'>cause</span>(<span class='kw-2'>&amp;</span><span class='ident'>ewd</span>) {
<span class='prelude-val'>Some</span>(_) <span class='op'>=&gt;</span> <span class='macro'>assert</span><span class='macro'>!</span>(<span class='bool-val'>false</span>),
<span class='prelude-val'>None</span> <span class='op'>=&gt;</span> <span class='macro'>assert</span><span class='macro'>!</span>(<span class='bool-val'>true</span>),
}
<span class='kw'>let</span> <span class='ident'>_formated_err</span> <span class='op'>=</span> <span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;{}&quot;</span>, <span class='ident'>ewd</span>);
<span class='kw'>let</span> <span class='ident'>ewod</span> <span class='op'>=</span> <span class='ident'>custom_error</span>::<span class='ident'>Error</span>::<span class='ident'>new</span>(<span class='ident'>desc</span>, <span class='prelude-val'>None</span>);
<span class='kw'>let</span> <span class='ident'>_formated_err</span> <span class='op'>=</span> <span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;{}&quot;</span>, <span class='ident'>ewod</span>);
}
}
<span class='attribute'>#[<span class='ident'>cfg</span>(<span class='ident'>test</span>)]</span>
<span class='kw'>mod</span> <span class='ident'>tests_std_err</span> {
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>error</span>::<span class='ident'>Error</span>;
<span class='kw'>use</span> <span class='ident'>custom_error</span>::<span class='ident'>pie2io</span>;
<span class='attribute'>#[<span class='ident'>test</span>]</span>
<span class='kw'>fn</span> <span class='ident'>test_parse_errors</span>() {
<span class='kw'>let</span> <span class='ident'>nan</span> <span class='op'>=</span> <span class='string'>&quot;2a&quot;</span>.<span class='ident'>to_string</span>();
<span class='kw'>match</span> <span class='ident'>nan</span>.<span class='ident'>parse</span>::<span class='op'>&lt;</span><span class='ident'>u8</span><span class='op'>&gt;</span>().<span class='ident'>map_err</span>(<span class='ident'>pie2io</span>) {
<span class='prelude-val'>Ok</span>(_) <span class='op'>=&gt;</span> <span class='macro'>assert</span><span class='macro'>!</span>(<span class='bool-val'>false</span>),
<span class='prelude-val'>Err</span>(<span class='ident'>x</span>) <span class='op'>=&gt;</span> <span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='string'>&quot;Integer parsing error&quot;</span>, <span class='ident'>x</span>.<span class='ident'>description</span>()),
}
}
}
</pre>
</section>
<section id='search' class="content hidden"></section>
<section class="footer"></section>
<aside id="help" class="hidden">
<div>
<h1 class="hidden">Help</h1>
<div class="shortcuts">
<h2>Keyboard Shortcuts</h2>
<dl>
<dt>?</dt>
<dd>Show this help dialog</dd>
<dt>S</dt>
<dd>Focus the search field</dd>
<dt>&larrb;</dt>
<dd>Move up in search results</dd>
<dt>&rarrb;</dt>
<dd>Move down in search results</dd>
<dt>&#9166;</dt>
<dd>Go to active search result</dd>
<dt>+</dt>
<dd>Collapse/expand all sections</dd>
</dl>
</div>
<div class="infos">
<h2>Search Tricks</h2>
<p>
Prefix searches with a type followed by a colon (e.g.
<code>fn:</code>) to restrict the search to a given type.
</p>
<p>
Accepted types are: <code>fn</code>, <code>mod</code>,
<code>struct</code>, <code>enum</code>,
<code>trait</code>, <code>type</code>, <code>macro</code>,
and <code>const</code>.
</p>
<p>
Search functions by type signature (e.g.
<code>vec -> usize</code> or <code>* -> vec</code>)
</p>
</div>
</div>
</aside>
<script>
window.rootPath = "../../../";
window.currentCrate = "rusty_secrets";
window.playgroundUrl = "";
</script>
<script src="../../../jquery.js"></script>
<script src="../../../main.js"></script>
<script defer src="../../../search-index.js"></script>
</body>
</html>

View File

@ -0,0 +1,290 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="rustdoc">
<meta name="description" content="Source to the Rust file `src/gf256.rs`.">
<meta name="keywords" content="rust, rustlang, rust-lang">
<title>gf256.rs.html -- source</title>
<link rel="stylesheet" type="text/css" href="../../../rustdoc.css">
<link rel="stylesheet" type="text/css" href="../../../main.css">
</head>
<body class="rustdoc">
<!--[if lte IE 8]>
<div class="warning">
This old browser is unsupported and will most likely display funky
things.
</div>
<![endif]-->
<nav class="sidebar">
</nav>
<nav class="sub">
<form class="search-form js-only">
<div class="search-container">
<input class="search-input" name="search"
autocomplete="off"
placeholder="Click or press S to search, ? for more options…"
type="search">
</div>
</form>
</nav>
<section id='main' class="content source"><pre class="line-numbers"><span id="1"> 1</span>
<span id="2"> 2</span>
<span id="3"> 3</span>
<span id="4"> 4</span>
<span id="5"> 5</span>
<span id="6"> 6</span>
<span id="7"> 7</span>
<span id="8"> 8</span>
<span id="9"> 9</span>
<span id="10">10</span>
<span id="11">11</span>
<span id="12">12</span>
<span id="13">13</span>
<span id="14">14</span>
<span id="15">15</span>
<span id="16">16</span>
<span id="17">17</span>
<span id="18">18</span>
<span id="19">19</span>
<span id="20">20</span>
<span id="21">21</span>
<span id="22">22</span>
<span id="23">23</span>
<span id="24">24</span>
<span id="25">25</span>
<span id="26">26</span>
<span id="27">27</span>
<span id="28">28</span>
<span id="29">29</span>
<span id="30">30</span>
<span id="31">31</span>
<span id="32">32</span>
<span id="33">33</span>
<span id="34">34</span>
<span id="35">35</span>
<span id="36">36</span>
<span id="37">37</span>
<span id="38">38</span>
<span id="39">39</span>
<span id="40">40</span>
<span id="41">41</span>
<span id="42">42</span>
<span id="43">43</span>
<span id="44">44</span>
<span id="45">45</span>
<span id="46">46</span>
<span id="47">47</span>
<span id="48">48</span>
<span id="49">49</span>
<span id="50">50</span>
<span id="51">51</span>
<span id="52">52</span>
<span id="53">53</span>
<span id="54">54</span>
<span id="55">55</span>
<span id="56">56</span>
<span id="57">57</span>
<span id="58">58</span>
<span id="59">59</span>
<span id="60">60</span>
<span id="61">61</span>
<span id="62">62</span>
<span id="63">63</span>
<span id="64">64</span>
<span id="65">65</span>
<span id="66">66</span>
<span id="67">67</span>
<span id="68">68</span>
<span id="69">69</span>
<span id="70">70</span>
<span id="71">71</span>
<span id="72">72</span>
<span id="73">73</span>
<span id="74">74</span>
<span id="75">75</span>
<span id="76">76</span>
<span id="77">77</span>
<span id="78">78</span>
<span id="79">79</span>
<span id="80">80</span>
<span id="81">81</span>
<span id="82">82</span>
<span id="83">83</span>
<span id="84">84</span>
<span id="85">85</span>
<span id="86">86</span>
<span id="87">87</span>
<span id="88">88</span>
<span id="89">89</span>
<span id="90">90</span>
</pre><pre class='rust '>
<span class='doccomment'>//! This module provides the Gf256 type which is used to represent</span>
<span class='doccomment'>//! elements of a finite field with 256 elements.</span>
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>ops</span>::{<span class='ident'>Add</span>, <span class='ident'>Div</span>, <span class='ident'>Mul</span>, <span class='ident'>Sub</span>};
<span class='macro'>include</span><span class='macro'>!</span>(<span class='macro'>concat</span><span class='macro'>!</span>(<span class='macro'>env</span><span class='macro'>!</span>(<span class='string'>&quot;OUT_DIR&quot;</span>), <span class='string'>&quot;/nothinghardcoded.rs&quot;</span>));
<span class='kw'>fn</span> <span class='ident'>get_tables</span>() <span class='op'>-&gt;</span> <span class='kw-2'>&amp;</span><span class='lifetime'>&#39;static</span> <span class='ident'>Tables</span> {
<span class='kw-2'>&amp;</span><span class='ident'>TABLES</span>
}
<span class='doccomment'>/// Type for elements of a finite field with 256 elements</span>
<span class='attribute'>#[<span class='ident'>derive</span>(<span class='ident'>Copy</span>,<span class='ident'>Clone</span>,<span class='ident'>PartialEq</span>,<span class='ident'>Eq</span>)]</span>
<span class='kw'>pub</span> <span class='kw'>struct</span> <span class='ident'>Gf256</span> {
<span class='kw'>pub</span> <span class='ident'>poly</span>: <span class='ident'>u8</span>,
}
<span class='kw'>impl</span> <span class='ident'>Gf256</span> {
<span class='doccomment'>/// returns the additive neutral element of the field</span>
<span class='attribute'>#[<span class='ident'>inline</span>]</span>
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>zero</span>() <span class='op'>-&gt;</span> <span class='ident'>Gf256</span> {
<span class='ident'>Gf256</span> { <span class='ident'>poly</span>: <span class='number'>0</span> }
}
<span class='doccomment'>/// returns the multiplicative neutral element of the field</span>
<span class='attribute'>#[<span class='ident'>inline</span>]</span>
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>one</span>() <span class='op'>-&gt;</span> <span class='ident'>Gf256</span> {
<span class='ident'>Gf256</span> { <span class='ident'>poly</span>: <span class='number'>1</span> }
}
<span class='attribute'>#[<span class='ident'>inline</span>]</span>
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>from_byte</span>(<span class='ident'>b</span>: <span class='ident'>u8</span>) <span class='op'>-&gt;</span> <span class='ident'>Gf256</span> {
<span class='ident'>Gf256</span> { <span class='ident'>poly</span>: <span class='ident'>b</span> }
}
<span class='attribute'>#[<span class='ident'>inline</span>]</span>
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>to_byte</span>(<span class='kw-2'>&amp;</span><span class='self'>self</span>) <span class='op'>-&gt;</span> <span class='ident'>u8</span> {
<span class='self'>self</span>.<span class='ident'>poly</span>
}
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>log</span>(<span class='kw-2'>&amp;</span><span class='self'>self</span>) <span class='op'>-&gt;</span> <span class='prelude-ty'>Option</span><span class='op'>&lt;</span><span class='ident'>u8</span><span class='op'>&gt;</span> {
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>poly</span> <span class='op'>==</span> <span class='number'>0</span> {
<span class='prelude-val'>None</span>
} <span class='kw'>else</span> {
<span class='kw'>let</span> <span class='ident'>tabs</span> <span class='op'>=</span> <span class='ident'>get_tables</span>();
<span class='prelude-val'>Some</span>(<span class='ident'>tabs</span>.<span class='ident'>log</span>[<span class='self'>self</span>.<span class='ident'>poly</span> <span class='kw'>as</span> <span class='ident'>usize</span>])
}
}
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>exp</span>(<span class='ident'>power</span>: <span class='ident'>u8</span>) <span class='op'>-&gt;</span> <span class='ident'>Gf256</span> {
<span class='kw'>let</span> <span class='ident'>tabs</span> <span class='op'>=</span> <span class='ident'>get_tables</span>();
<span class='ident'>Gf256</span> { <span class='ident'>poly</span>: <span class='ident'>tabs</span>.<span class='ident'>exp</span>[<span class='ident'>power</span> <span class='kw'>as</span> <span class='ident'>usize</span>] }
}
}
<span class='kw'>impl</span> <span class='ident'>Add</span><span class='op'>&lt;</span><span class='ident'>Gf256</span><span class='op'>&gt;</span> <span class='kw'>for</span> <span class='ident'>Gf256</span> {
<span class='kw'>type</span> <span class='ident'>Output</span> <span class='op'>=</span> <span class='ident'>Gf256</span>;
<span class='attribute'>#[<span class='ident'>inline</span>]</span>
<span class='kw'>fn</span> <span class='ident'>add</span>(<span class='self'>self</span>, <span class='ident'>rhs</span>: <span class='ident'>Gf256</span>) <span class='op'>-&gt;</span> <span class='ident'>Gf256</span> {
<span class='ident'>Gf256</span>::<span class='ident'>from_byte</span>(<span class='self'>self</span>.<span class='ident'>poly</span> <span class='op'>^</span> <span class='ident'>rhs</span>.<span class='ident'>poly</span>)
}
}
<span class='kw'>impl</span> <span class='ident'>Sub</span><span class='op'>&lt;</span><span class='ident'>Gf256</span><span class='op'>&gt;</span> <span class='kw'>for</span> <span class='ident'>Gf256</span> {
<span class='kw'>type</span> <span class='ident'>Output</span> <span class='op'>=</span> <span class='ident'>Gf256</span>;
<span class='attribute'>#[<span class='ident'>inline</span>]</span>
<span class='kw'>fn</span> <span class='ident'>sub</span>(<span class='self'>self</span>, <span class='ident'>rhs</span>: <span class='ident'>Gf256</span>) <span class='op'>-&gt;</span> <span class='ident'>Gf256</span> {
<span class='ident'>Gf256</span>::<span class='ident'>from_byte</span>(<span class='self'>self</span>.<span class='ident'>poly</span> <span class='op'>^</span> <span class='ident'>rhs</span>.<span class='ident'>poly</span>)
}
}
<span class='kw'>impl</span> <span class='ident'>Mul</span><span class='op'>&lt;</span><span class='ident'>Gf256</span><span class='op'>&gt;</span> <span class='kw'>for</span> <span class='ident'>Gf256</span> {
<span class='kw'>type</span> <span class='ident'>Output</span> <span class='op'>=</span> <span class='ident'>Gf256</span>;
<span class='kw'>fn</span> <span class='ident'>mul</span>(<span class='self'>self</span>, <span class='ident'>rhs</span>: <span class='ident'>Gf256</span>) <span class='op'>-&gt;</span> <span class='ident'>Gf256</span> {
<span class='kw'>if</span> <span class='kw'>let</span> (<span class='prelude-val'>Some</span>(<span class='ident'>l1</span>), <span class='prelude-val'>Some</span>(<span class='ident'>l2</span>)) <span class='op'>=</span> (<span class='self'>self</span>.<span class='ident'>log</span>(), <span class='ident'>rhs</span>.<span class='ident'>log</span>()) {
<span class='kw'>let</span> <span class='ident'>tmp</span> <span class='op'>=</span> ((<span class='ident'>l1</span> <span class='kw'>as</span> <span class='ident'>u16</span>) <span class='op'>+</span> (<span class='ident'>l2</span> <span class='kw'>as</span> <span class='ident'>u16</span>)) <span class='op'>%</span> <span class='number'>255</span>;
<span class='ident'>Gf256</span>::<span class='ident'>exp</span>(<span class='ident'>tmp</span> <span class='kw'>as</span> <span class='ident'>u8</span>)
} <span class='kw'>else</span> {
<span class='ident'>Gf256</span> { <span class='ident'>poly</span>: <span class='number'>0</span> }
}
}
}
<span class='kw'>impl</span> <span class='ident'>Div</span><span class='op'>&lt;</span><span class='ident'>Gf256</span><span class='op'>&gt;</span> <span class='kw'>for</span> <span class='ident'>Gf256</span> {
<span class='kw'>type</span> <span class='ident'>Output</span> <span class='op'>=</span> <span class='ident'>Gf256</span>;
<span class='kw'>fn</span> <span class='ident'>div</span>(<span class='self'>self</span>, <span class='ident'>rhs</span>: <span class='ident'>Gf256</span>) <span class='op'>-&gt;</span> <span class='ident'>Gf256</span> {
<span class='kw'>let</span> <span class='ident'>l2</span> <span class='op'>=</span> <span class='ident'>rhs</span>.<span class='ident'>log</span>().<span class='ident'>expect</span>(<span class='string'>&quot;division by zero&quot;</span>);
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>l1</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>log</span>() {
<span class='kw'>let</span> <span class='ident'>tmp</span> <span class='op'>=</span> ((<span class='ident'>l1</span> <span class='kw'>as</span> <span class='ident'>u16</span>) <span class='op'>+</span> <span class='number'>255</span> <span class='op'>-</span> (<span class='ident'>l2</span> <span class='kw'>as</span> <span class='ident'>u16</span>)) <span class='op'>%</span> <span class='number'>255</span>;
<span class='ident'>Gf256</span>::<span class='ident'>exp</span>(<span class='ident'>tmp</span> <span class='kw'>as</span> <span class='ident'>u8</span>)
} <span class='kw'>else</span> {
<span class='ident'>Gf256</span> { <span class='ident'>poly</span>: <span class='number'>0</span> }
}
}
}
</pre>
</section>
<section id='search' class="content hidden"></section>
<section class="footer"></section>
<aside id="help" class="hidden">
<div>
<h1 class="hidden">Help</h1>
<div class="shortcuts">
<h2>Keyboard Shortcuts</h2>
<dl>
<dt>?</dt>
<dd>Show this help dialog</dd>
<dt>S</dt>
<dd>Focus the search field</dd>
<dt>&larrb;</dt>
<dd>Move up in search results</dd>
<dt>&rarrb;</dt>
<dd>Move down in search results</dd>
<dt>&#9166;</dt>
<dd>Go to active search result</dd>
<dt>+</dt>
<dd>Collapse/expand all sections</dd>
</dl>
</div>
<div class="infos">
<h2>Search Tricks</h2>
<p>
Prefix searches with a type followed by a colon (e.g.
<code>fn:</code>) to restrict the search to a given type.
</p>
<p>
Accepted types are: <code>fn</code>, <code>mod</code>,
<code>struct</code>, <code>enum</code>,
<code>trait</code>, <code>type</code>, <code>macro</code>,
and <code>const</code>.
</p>
<p>
Search functions by type signature (e.g.
<code>vec -> usize</code> or <code>* -> vec</code>)
</p>
</div>
</div>
</aside>
<script>
window.rootPath = "../../../";
window.currentCrate = "rusty_secrets";
window.playgroundUrl = "";
</script>
<script src="../../../jquery.js"></script>
<script src="../../../main.js"></script>
<script defer src="../../../search-index.js"></script>
</body>
</html>

View File

@ -0,0 +1,190 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="rustdoc">
<meta name="description" content="Source to the Rust file `src/interpolation.rs`.">
<meta name="keywords" content="rust, rustlang, rust-lang">
<title>interpolation.rs.html -- source</title>
<link rel="stylesheet" type="text/css" href="../../../rustdoc.css">
<link rel="stylesheet" type="text/css" href="../../../main.css">
</head>
<body class="rustdoc">
<!--[if lte IE 8]>
<div class="warning">
This old browser is unsupported and will most likely display funky
things.
</div>
<![endif]-->
<nav class="sidebar">
</nav>
<nav class="sub">
<form class="search-form js-only">
<div class="search-container">
<input class="search-input" name="search"
autocomplete="off"
placeholder="Click or press S to search, ? for more options…"
type="search">
</div>
</form>
</nav>
<section id='main' class="content source"><pre class="line-numbers"><span id="1"> 1</span>
<span id="2"> 2</span>
<span id="3"> 3</span>
<span id="4"> 4</span>
<span id="5"> 5</span>
<span id="6"> 6</span>
<span id="7"> 7</span>
<span id="8"> 8</span>
<span id="9"> 9</span>
<span id="10">10</span>
<span id="11">11</span>
<span id="12">12</span>
<span id="13">13</span>
<span id="14">14</span>
<span id="15">15</span>
<span id="16">16</span>
<span id="17">17</span>
<span id="18">18</span>
<span id="19">19</span>
<span id="20">20</span>
<span id="21">21</span>
<span id="22">22</span>
<span id="23">23</span>
<span id="24">24</span>
<span id="25">25</span>
<span id="26">26</span>
<span id="27">27</span>
<span id="28">28</span>
<span id="29">29</span>
<span id="30">30</span>
<span id="31">31</span>
<span id="32">32</span>
<span id="33">33</span>
<span id="34">34</span>
<span id="35">35</span>
<span id="36">36</span>
<span id="37">37</span>
<span id="38">38</span>
<span id="39">39</span>
<span id="40">40</span>
</pre><pre class='rust '>
<span class='kw'>use</span> <span class='ident'>gf256</span>::<span class='ident'>Gf256</span>;
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>io</span>;
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>io</span>::<span class='ident'>prelude</span>::<span class='op'>*</span>;
<span class='doccomment'>/// evaluates a polynomial at x=1, 2, 3, ... n (inclusive)</span>
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>encode</span><span class='op'>&lt;</span><span class='ident'>W</span>: <span class='ident'>Write</span><span class='op'>&gt;</span>(<span class='ident'>src</span>: <span class='kw-2'>&amp;</span>[<span class='ident'>u8</span>], <span class='ident'>n</span>: <span class='ident'>u8</span>, <span class='ident'>w</span>: <span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> <span class='ident'>W</span>) <span class='op'>-&gt;</span> <span class='ident'>io</span>::<span class='prelude-ty'>Result</span><span class='op'>&lt;</span>()<span class='op'>&gt;</span> {
<span class='kw'>for</span> <span class='ident'>raw_x</span> <span class='kw'>in</span> <span class='number'>1</span>..((<span class='ident'>n</span> <span class='kw'>as</span> <span class='ident'>u16</span>) <span class='op'>+</span> <span class='number'>1</span>) {
<span class='kw'>let</span> <span class='ident'>x</span> <span class='op'>=</span> <span class='ident'>Gf256</span>::<span class='ident'>from_byte</span>(<span class='ident'>raw_x</span> <span class='kw'>as</span> <span class='ident'>u8</span>);
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>fac</span> <span class='op'>=</span> <span class='ident'>Gf256</span>::<span class='ident'>one</span>();
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>acc</span> <span class='op'>=</span> <span class='ident'>Gf256</span>::<span class='ident'>zero</span>();
<span class='kw'>for</span> <span class='kw-2'>&amp;</span><span class='ident'>coeff</span> <span class='kw'>in</span> <span class='ident'>src</span>.<span class='ident'>iter</span>() {
<span class='ident'>acc</span> <span class='op'>=</span> <span class='ident'>acc</span> <span class='op'>+</span> <span class='ident'>fac</span> <span class='op'>*</span> <span class='ident'>Gf256</span>::<span class='ident'>from_byte</span>(<span class='ident'>coeff</span>);
<span class='ident'>fac</span> <span class='op'>=</span> <span class='ident'>fac</span> <span class='op'>*</span> <span class='ident'>x</span>;
}
<span class='macro'>try</span><span class='macro'>!</span>(<span class='ident'>w</span>.<span class='ident'>write</span>(<span class='kw-2'>&amp;</span>[<span class='ident'>acc</span>.<span class='ident'>to_byte</span>()]));
}
<span class='prelude-val'>Ok</span>(())
}
<span class='doccomment'>/// evaluates an interpolated polynomial at `Gf256::zero()` where</span>
<span class='doccomment'>/// the polynomial is determined using Lagrangian interpolation</span>
<span class='doccomment'>/// based on the given x/y coordinates `src`.</span>
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>lagrange_interpolate</span>(<span class='ident'>src</span>: <span class='kw-2'>&amp;</span>[(<span class='ident'>u8</span>, <span class='ident'>u8</span>)]) <span class='op'>-&gt;</span> <span class='ident'>u8</span> {
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>sum</span> <span class='op'>=</span> <span class='ident'>Gf256</span>::<span class='ident'>zero</span>();
<span class='kw'>for</span> (<span class='ident'>i</span>, <span class='kw-2'>&amp;</span>(<span class='ident'>raw_xi</span>, <span class='ident'>raw_yi</span>)) <span class='kw'>in</span> <span class='ident'>src</span>.<span class='ident'>iter</span>().<span class='ident'>enumerate</span>() {
<span class='kw'>let</span> <span class='ident'>xi</span> <span class='op'>=</span> <span class='ident'>Gf256</span>::<span class='ident'>from_byte</span>(<span class='ident'>raw_xi</span>);
<span class='kw'>let</span> <span class='ident'>yi</span> <span class='op'>=</span> <span class='ident'>Gf256</span>::<span class='ident'>from_byte</span>(<span class='ident'>raw_yi</span>);
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>prod</span> <span class='op'>=</span> <span class='ident'>Gf256</span>::<span class='ident'>one</span>();
<span class='kw'>for</span> (<span class='ident'>j</span>, <span class='kw-2'>&amp;</span>(<span class='ident'>raw_xj</span>, _)) <span class='kw'>in</span> <span class='ident'>src</span>.<span class='ident'>iter</span>().<span class='ident'>enumerate</span>() {
<span class='kw'>if</span> <span class='ident'>i</span> <span class='op'>!=</span> <span class='ident'>j</span> {
<span class='kw'>let</span> <span class='ident'>xj</span> <span class='op'>=</span> <span class='ident'>Gf256</span>::<span class='ident'>from_byte</span>(<span class='ident'>raw_xj</span>);
<span class='kw'>let</span> <span class='ident'>delta</span> <span class='op'>=</span> <span class='ident'>xi</span> <span class='op'>-</span> <span class='ident'>xj</span>;
<span class='macro'>assert</span><span class='macro'>!</span>(<span class='ident'>delta</span>.<span class='ident'>poly</span> <span class='op'>!=</span> <span class='number'>0</span>, <span class='string'>&quot;Duplicate shares&quot;</span>);
<span class='ident'>prod</span> <span class='op'>=</span> <span class='ident'>prod</span> <span class='op'>*</span> <span class='ident'>xj</span> <span class='op'>/</span> <span class='ident'>delta</span>;
}
}
<span class='ident'>sum</span> <span class='op'>=</span> <span class='ident'>sum</span> <span class='op'>+</span> <span class='ident'>prod</span> <span class='op'>*</span> <span class='ident'>yi</span>;
}
<span class='ident'>sum</span>.<span class='ident'>to_byte</span>()
}
</pre>
</section>
<section id='search' class="content hidden"></section>
<section class="footer"></section>
<aside id="help" class="hidden">
<div>
<h1 class="hidden">Help</h1>
<div class="shortcuts">
<h2>Keyboard Shortcuts</h2>
<dl>
<dt>?</dt>
<dd>Show this help dialog</dd>
<dt>S</dt>
<dd>Focus the search field</dd>
<dt>&larrb;</dt>
<dd>Move up in search results</dd>
<dt>&rarrb;</dt>
<dd>Move down in search results</dd>
<dt>&#9166;</dt>
<dd>Go to active search result</dd>
<dt>+</dt>
<dd>Collapse/expand all sections</dd>
</dl>
</div>
<div class="infos">
<h2>Search Tricks</h2>
<p>
Prefix searches with a type followed by a colon (e.g.
<code>fn:</code>) to restrict the search to a given type.
</p>
<p>
Accepted types are: <code>fn</code>, <code>mod</code>,
<code>struct</code>, <code>enum</code>,
<code>trait</code>, <code>type</code>, <code>macro</code>,
and <code>const</code>.
</p>
<p>
Search functions by type signature (e.g.
<code>vec -> usize</code> or <code>* -> vec</code>)
</p>
</div>
</div>
</aside>
<script>
window.rootPath = "../../../";
window.currentCrate = "rusty_secrets";
window.playgroundUrl = "";
</script>
<script src="../../../jquery.js"></script>
<script src="../../../main.js"></script>
<script defer src="../../../search-index.js"></script>
</body>
</html>

View File

@ -0,0 +1,176 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="rustdoc">
<meta name="description" content="Source to the Rust file `src/lib.rs`.">
<meta name="keywords" content="rust, rustlang, rust-lang">
<title>lib.rs.html -- source</title>
<link rel="stylesheet" type="text/css" href="../../../rustdoc.css">
<link rel="stylesheet" type="text/css" href="../../../main.css">
</head>
<body class="rustdoc">
<!--[if lte IE 8]>
<div class="warning">
This old browser is unsupported and will most likely display funky
things.
</div>
<![endif]-->
<nav class="sidebar">
</nav>
<nav class="sub">
<form class="search-form js-only">
<div class="search-container">
<input class="search-input" name="search"
autocomplete="off"
placeholder="Click or press S to search, ? for more options…"
type="search">
</div>
</form>
</nav>
<section id='main' class="content source"><pre class="line-numbers"><span id="1"> 1</span>
<span id="2"> 2</span>
<span id="3"> 3</span>
<span id="4"> 4</span>
<span id="5"> 5</span>
<span id="6"> 6</span>
<span id="7"> 7</span>
<span id="8"> 8</span>
<span id="9"> 9</span>
<span id="10">10</span>
<span id="11">11</span>
<span id="12">12</span>
<span id="13">13</span>
<span id="14">14</span>
<span id="15">15</span>
<span id="16">16</span>
<span id="17">17</span>
<span id="18">18</span>
<span id="19">19</span>
<span id="20">20</span>
<span id="21">21</span>
<span id="22">22</span>
<span id="23">23</span>
<span id="24">24</span>
<span id="25">25</span>
<span id="26">26</span>
<span id="27">27</span>
<span id="28">28</span>
<span id="29">29</span>
<span id="30">30</span>
<span id="31">31</span>
<span id="32">32</span>
<span id="33">33</span>
</pre><pre class='rust '>
<span class='attribute'>#<span class='op'>!</span>[<span class='ident'>deny</span>(
<span class='ident'>missing_docs</span>,
<span class='ident'>missing_debug_implementations</span>, <span class='ident'>missing_copy_implementations</span>,
<span class='ident'>trivial_casts</span>, <span class='ident'>trivial_numeric_casts</span>,
<span class='ident'>unsafe_code</span>, <span class='ident'>unstable_features</span>,
<span class='ident'>unused_import_braces</span>, <span class='ident'>unused_qualifications</span>
)]</span>
<span class='doccomment'>//! `RustySecrets` implements Shamir Secret Sharing in Rust. It provides the possibility to sign shares.</span>
<span class='kw'>extern</span> <span class='kw'>crate</span> <span class='ident'>protobuf</span>;
<span class='kw'>extern</span> <span class='kw'>crate</span> <span class='ident'>rustc_serialize</span> <span class='kw'>as</span> <span class='ident'>serialize</span>;
<span class='kw'>extern</span> <span class='kw'>crate</span> <span class='ident'>rand</span>;
<span class='kw'>extern</span> <span class='kw'>crate</span> <span class='ident'>merkle_sigs</span>;
<span class='kw'>extern</span> <span class='kw'>crate</span> <span class='ident'>ring</span>;
<span class='kw'>use</span> <span class='ident'>ring</span>::<span class='ident'>digest</span>::{<span class='ident'>Algorithm</span>, <span class='ident'>SHA512</span>};
<span class='attribute'>#[<span class='ident'>allow</span>(<span class='ident'>non_upper_case_globals</span>)]</span>
<span class='kw'>static</span> <span class='ident'>digest</span>: <span class='kw-2'>&amp;</span><span class='lifetime'>&#39;static</span> <span class='ident'>Algorithm</span> <span class='op'>=</span> <span class='kw-2'>&amp;</span><span class='ident'>SHA512</span>;
<span class='kw'>mod</span> <span class='ident'>custom_error</span>;
<span class='kw'>mod</span> <span class='ident'>gf256</span>;
<span class='kw'>mod</span> <span class='ident'>interpolation</span>;
<span class='kw'>mod</span> <span class='ident'>share_data</span>;
<span class='kw'>mod</span> <span class='ident'>share_format</span>;
<span class='kw'>mod</span> <span class='ident'>sss</span>;
<span class='kw'>mod</span> <span class='ident'>validation</span>;
<span class='kw'>pub</span> <span class='kw'>use</span> <span class='ident'>sss</span>::<span class='ident'>generate_shares</span>;
<span class='kw'>pub</span> <span class='kw'>use</span> <span class='ident'>sss</span>::<span class='ident'>recover_secret</span>;
<span class='attribute'>#[<span class='ident'>cfg</span>(<span class='ident'>test</span>)]</span>
<span class='kw'>mod</span> <span class='ident'>tests</span>;
</pre>
</section>
<section id='search' class="content hidden"></section>
<section class="footer"></section>
<aside id="help" class="hidden">
<div>
<h1 class="hidden">Help</h1>
<div class="shortcuts">
<h2>Keyboard Shortcuts</h2>
<dl>
<dt>?</dt>
<dd>Show this help dialog</dd>
<dt>S</dt>
<dd>Focus the search field</dd>
<dt>&larrb;</dt>
<dd>Move up in search results</dd>
<dt>&rarrb;</dt>
<dd>Move down in search results</dd>
<dt>&#9166;</dt>
<dd>Go to active search result</dd>
<dt>+</dt>
<dd>Collapse/expand all sections</dd>
</dl>
</div>
<div class="infos">
<h2>Search Tricks</h2>
<p>
Prefix searches with a type followed by a colon (e.g.
<code>fn:</code>) to restrict the search to a given type.
</p>
<p>
Accepted types are: <code>fn</code>, <code>mod</code>,
<code>struct</code>, <code>enum</code>,
<code>trait</code>, <code>type</code>, <code>macro</code>,
and <code>const</code>.
</p>
<p>
Search functions by type signature (e.g.
<code>vec -> usize</code> or <code>* -> vec</code>)
</p>
</div>
</div>
</aside>
<script>
window.rootPath = "../../../";
window.currentCrate = "rusty_secrets";
window.playgroundUrl = "";
</script>
<script src="../../../jquery.js"></script>
<script src="../../../main.js"></script>
<script defer src="../../../search-index.js"></script>
</body>
</html>

View File

@ -0,0 +1,800 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="rustdoc">
<meta name="description" content="Source to the Rust file `src/share_data.rs`.">
<meta name="keywords" content="rust, rustlang, rust-lang">
<title>share_data.rs.html -- source</title>
<link rel="stylesheet" type="text/css" href="../../../rustdoc.css">
<link rel="stylesheet" type="text/css" href="../../../main.css">
</head>
<body class="rustdoc">
<!--[if lte IE 8]>
<div class="warning">
This old browser is unsupported and will most likely display funky
things.
</div>
<![endif]-->
<nav class="sidebar">
</nav>
<nav class="sub">
<form class="search-form js-only">
<div class="search-container">
<input class="search-input" name="search"
autocomplete="off"
placeholder="Click or press S to search, ? for more options…"
type="search">
</div>
</form>
</nav>
<section id='main' class="content source"><pre class="line-numbers"><span id="1"> 1</span>
<span id="2"> 2</span>
<span id="3"> 3</span>
<span id="4"> 4</span>
<span id="5"> 5</span>
<span id="6"> 6</span>
<span id="7"> 7</span>
<span id="8"> 8</span>
<span id="9"> 9</span>
<span id="10"> 10</span>
<span id="11"> 11</span>
<span id="12"> 12</span>
<span id="13"> 13</span>
<span id="14"> 14</span>
<span id="15"> 15</span>
<span id="16"> 16</span>
<span id="17"> 17</span>
<span id="18"> 18</span>
<span id="19"> 19</span>
<span id="20"> 20</span>
<span id="21"> 21</span>
<span id="22"> 22</span>
<span id="23"> 23</span>
<span id="24"> 24</span>
<span id="25"> 25</span>
<span id="26"> 26</span>
<span id="27"> 27</span>
<span id="28"> 28</span>
<span id="29"> 29</span>
<span id="30"> 30</span>
<span id="31"> 31</span>
<span id="32"> 32</span>
<span id="33"> 33</span>
<span id="34"> 34</span>
<span id="35"> 35</span>
<span id="36"> 36</span>
<span id="37"> 37</span>
<span id="38"> 38</span>
<span id="39"> 39</span>
<span id="40"> 40</span>
<span id="41"> 41</span>
<span id="42"> 42</span>
<span id="43"> 43</span>
<span id="44"> 44</span>
<span id="45"> 45</span>
<span id="46"> 46</span>
<span id="47"> 47</span>
<span id="48"> 48</span>
<span id="49"> 49</span>
<span id="50"> 50</span>
<span id="51"> 51</span>
<span id="52"> 52</span>
<span id="53"> 53</span>
<span id="54"> 54</span>
<span id="55"> 55</span>
<span id="56"> 56</span>
<span id="57"> 57</span>
<span id="58"> 58</span>
<span id="59"> 59</span>
<span id="60"> 60</span>
<span id="61"> 61</span>
<span id="62"> 62</span>
<span id="63"> 63</span>
<span id="64"> 64</span>
<span id="65"> 65</span>
<span id="66"> 66</span>
<span id="67"> 67</span>
<span id="68"> 68</span>
<span id="69"> 69</span>
<span id="70"> 70</span>
<span id="71"> 71</span>
<span id="72"> 72</span>
<span id="73"> 73</span>
<span id="74"> 74</span>
<span id="75"> 75</span>
<span id="76"> 76</span>
<span id="77"> 77</span>
<span id="78"> 78</span>
<span id="79"> 79</span>
<span id="80"> 80</span>
<span id="81"> 81</span>
<span id="82"> 82</span>
<span id="83"> 83</span>
<span id="84"> 84</span>
<span id="85"> 85</span>
<span id="86"> 86</span>
<span id="87"> 87</span>
<span id="88"> 88</span>
<span id="89"> 89</span>
<span id="90"> 90</span>
<span id="91"> 91</span>
<span id="92"> 92</span>
<span id="93"> 93</span>
<span id="94"> 94</span>
<span id="95"> 95</span>
<span id="96"> 96</span>
<span id="97"> 97</span>
<span id="98"> 98</span>
<span id="99"> 99</span>
<span id="100">100</span>
<span id="101">101</span>
<span id="102">102</span>
<span id="103">103</span>
<span id="104">104</span>
<span id="105">105</span>
<span id="106">106</span>
<span id="107">107</span>
<span id="108">108</span>
<span id="109">109</span>
<span id="110">110</span>
<span id="111">111</span>
<span id="112">112</span>
<span id="113">113</span>
<span id="114">114</span>
<span id="115">115</span>
<span id="116">116</span>
<span id="117">117</span>
<span id="118">118</span>
<span id="119">119</span>
<span id="120">120</span>
<span id="121">121</span>
<span id="122">122</span>
<span id="123">123</span>
<span id="124">124</span>
<span id="125">125</span>
<span id="126">126</span>
<span id="127">127</span>
<span id="128">128</span>
<span id="129">129</span>
<span id="130">130</span>
<span id="131">131</span>
<span id="132">132</span>
<span id="133">133</span>
<span id="134">134</span>
<span id="135">135</span>
<span id="136">136</span>
<span id="137">137</span>
<span id="138">138</span>
<span id="139">139</span>
<span id="140">140</span>
<span id="141">141</span>
<span id="142">142</span>
<span id="143">143</span>
<span id="144">144</span>
<span id="145">145</span>
<span id="146">146</span>
<span id="147">147</span>
<span id="148">148</span>
<span id="149">149</span>
<span id="150">150</span>
<span id="151">151</span>
<span id="152">152</span>
<span id="153">153</span>
<span id="154">154</span>
<span id="155">155</span>
<span id="156">156</span>
<span id="157">157</span>
<span id="158">158</span>
<span id="159">159</span>
<span id="160">160</span>
<span id="161">161</span>
<span id="162">162</span>
<span id="163">163</span>
<span id="164">164</span>
<span id="165">165</span>
<span id="166">166</span>
<span id="167">167</span>
<span id="168">168</span>
<span id="169">169</span>
<span id="170">170</span>
<span id="171">171</span>
<span id="172">172</span>
<span id="173">173</span>
<span id="174">174</span>
<span id="175">175</span>
<span id="176">176</span>
<span id="177">177</span>
<span id="178">178</span>
<span id="179">179</span>
<span id="180">180</span>
<span id="181">181</span>
<span id="182">182</span>
<span id="183">183</span>
<span id="184">184</span>
<span id="185">185</span>
<span id="186">186</span>
<span id="187">187</span>
<span id="188">188</span>
<span id="189">189</span>
<span id="190">190</span>
<span id="191">191</span>
<span id="192">192</span>
<span id="193">193</span>
<span id="194">194</span>
<span id="195">195</span>
<span id="196">196</span>
<span id="197">197</span>
<span id="198">198</span>
<span id="199">199</span>
<span id="200">200</span>
<span id="201">201</span>
<span id="202">202</span>
<span id="203">203</span>
<span id="204">204</span>
<span id="205">205</span>
<span id="206">206</span>
<span id="207">207</span>
<span id="208">208</span>
<span id="209">209</span>
<span id="210">210</span>
<span id="211">211</span>
<span id="212">212</span>
<span id="213">213</span>
<span id="214">214</span>
<span id="215">215</span>
<span id="216">216</span>
<span id="217">217</span>
<span id="218">218</span>
<span id="219">219</span>
<span id="220">220</span>
<span id="221">221</span>
<span id="222">222</span>
<span id="223">223</span>
<span id="224">224</span>
<span id="225">225</span>
<span id="226">226</span>
<span id="227">227</span>
<span id="228">228</span>
<span id="229">229</span>
<span id="230">230</span>
<span id="231">231</span>
<span id="232">232</span>
<span id="233">233</span>
<span id="234">234</span>
<span id="235">235</span>
<span id="236">236</span>
<span id="237">237</span>
<span id="238">238</span>
<span id="239">239</span>
<span id="240">240</span>
<span id="241">241</span>
<span id="242">242</span>
<span id="243">243</span>
<span id="244">244</span>
<span id="245">245</span>
<span id="246">246</span>
<span id="247">247</span>
<span id="248">248</span>
<span id="249">249</span>
<span id="250">250</span>
<span id="251">251</span>
<span id="252">252</span>
<span id="253">253</span>
<span id="254">254</span>
<span id="255">255</span>
<span id="256">256</span>
<span id="257">257</span>
<span id="258">258</span>
<span id="259">259</span>
<span id="260">260</span>
<span id="261">261</span>
<span id="262">262</span>
<span id="263">263</span>
<span id="264">264</span>
<span id="265">265</span>
<span id="266">266</span>
<span id="267">267</span>
<span id="268">268</span>
<span id="269">269</span>
<span id="270">270</span>
<span id="271">271</span>
<span id="272">272</span>
<span id="273">273</span>
<span id="274">274</span>
<span id="275">275</span>
<span id="276">276</span>
<span id="277">277</span>
<span id="278">278</span>
<span id="279">279</span>
<span id="280">280</span>
<span id="281">281</span>
<span id="282">282</span>
<span id="283">283</span>
<span id="284">284</span>
<span id="285">285</span>
<span id="286">286</span>
<span id="287">287</span>
<span id="288">288</span>
<span id="289">289</span>
<span id="290">290</span>
<span id="291">291</span>
<span id="292">292</span>
<span id="293">293</span>
<span id="294">294</span>
<span id="295">295</span>
<span id="296">296</span>
<span id="297">297</span>
<span id="298">298</span>
<span id="299">299</span>
<span id="300">300</span>
<span id="301">301</span>
<span id="302">302</span>
<span id="303">303</span>
<span id="304">304</span>
<span id="305">305</span>
<span id="306">306</span>
<span id="307">307</span>
<span id="308">308</span>
<span id="309">309</span>
<span id="310">310</span>
<span id="311">311</span>
<span id="312">312</span>
<span id="313">313</span>
<span id="314">314</span>
<span id="315">315</span>
<span id="316">316</span>
<span id="317">317</span>
<span id="318">318</span>
<span id="319">319</span>
<span id="320">320</span>
<span id="321">321</span>
<span id="322">322</span>
<span id="323">323</span>
<span id="324">324</span>
<span id="325">325</span>
<span id="326">326</span>
<span id="327">327</span>
<span id="328">328</span>
<span id="329">329</span>
<span id="330">330</span>
<span id="331">331</span>
<span id="332">332</span>
<span id="333">333</span>
<span id="334">334</span>
<span id="335">335</span>
<span id="336">336</span>
<span id="337">337</span>
<span id="338">338</span>
<span id="339">339</span>
<span id="340">340</span>
<span id="341">341</span>
<span id="342">342</span>
<span id="343">343</span>
<span id="344">344</span>
<span id="345">345</span>
</pre><pre class='rust '>
<span class='comment'>// This file is generated. Do not edit</span>
<span class='comment'>// @generated</span>
<span class='comment'>// https://github.com/Manishearth/rust-clippy/issues/702</span>
<span class='attribute'>#<span class='op'>!</span>[<span class='ident'>allow</span>(<span class='ident'>unknown_lints</span>)]</span>
<span class='attribute'>#<span class='op'>!</span>[<span class='ident'>allow</span>(<span class='ident'>clippy</span>)]</span>
<span class='attribute'>#<span class='op'>!</span>[<span class='ident'>cfg_attr</span>(<span class='ident'>rustfmt</span>, <span class='ident'>rustfmt_skip</span>)]</span>
<span class='attribute'>#<span class='op'>!</span>[<span class='ident'>allow</span>(<span class='ident'>box_pointers</span>)]</span>
<span class='attribute'>#<span class='op'>!</span>[<span class='ident'>allow</span>(<span class='ident'>dead_code</span>)]</span>
<span class='attribute'>#<span class='op'>!</span>[<span class='ident'>allow</span>(<span class='ident'>non_camel_case_types</span>)]</span>
<span class='attribute'>#<span class='op'>!</span>[<span class='ident'>allow</span>(<span class='ident'>non_snake_case</span>)]</span>
<span class='attribute'>#<span class='op'>!</span>[<span class='ident'>allow</span>(<span class='ident'>non_upper_case_globals</span>)]</span>
<span class='attribute'>#<span class='op'>!</span>[<span class='ident'>allow</span>(<span class='ident'>trivial_casts</span>)]</span>
<span class='attribute'>#<span class='op'>!</span>[<span class='ident'>allow</span>(<span class='ident'>unsafe_code</span>)]</span>
<span class='attribute'>#<span class='op'>!</span>[<span class='ident'>allow</span>(<span class='ident'>unused_imports</span>)]</span>
<span class='attribute'>#<span class='op'>!</span>[<span class='ident'>allow</span>(<span class='ident'>unused_results</span>)]</span>
<span class='kw'>use</span> <span class='ident'>protobuf</span>::<span class='ident'>Message</span> <span class='kw'>as</span> <span class='ident'>Message_imported_for_functions</span>;
<span class='kw'>use</span> <span class='ident'>protobuf</span>::<span class='ident'>ProtobufEnum</span> <span class='kw'>as</span> <span class='ident'>ProtobufEnum_imported_for_functions</span>;
<span class='attribute'>#[<span class='ident'>derive</span>(<span class='ident'>Clone</span>,<span class='ident'>Default</span>)]</span>
<span class='kw'>pub</span> <span class='kw'>struct</span> <span class='ident'>ShareData</span> {
<span class='comment'>// message fields</span>
<span class='ident'>shamir_data</span>: ::<span class='ident'>protobuf</span>::<span class='ident'>SingularField</span><span class='op'>&lt;</span>::<span class='ident'>std</span>::<span class='ident'>vec</span>::<span class='ident'>Vec</span><span class='op'>&lt;</span><span class='ident'>u8</span><span class='op'>&gt;&gt;</span>,
<span class='ident'>signature</span>: ::<span class='ident'>protobuf</span>::<span class='ident'>RepeatedField</span><span class='op'>&lt;</span>::<span class='ident'>std</span>::<span class='ident'>vec</span>::<span class='ident'>Vec</span><span class='op'>&lt;</span><span class='ident'>u8</span><span class='op'>&gt;&gt;</span>,
<span class='ident'>proof</span>: ::<span class='ident'>protobuf</span>::<span class='ident'>SingularField</span><span class='op'>&lt;</span>::<span class='ident'>std</span>::<span class='ident'>vec</span>::<span class='ident'>Vec</span><span class='op'>&lt;</span><span class='ident'>u8</span><span class='op'>&gt;&gt;</span>,
<span class='comment'>// special fields</span>
<span class='ident'>unknown_fields</span>: ::<span class='ident'>protobuf</span>::<span class='ident'>UnknownFields</span>,
<span class='ident'>cached_size</span>: ::<span class='ident'>std</span>::<span class='ident'>cell</span>::<span class='ident'>Cell</span><span class='op'>&lt;</span><span class='ident'>u32</span><span class='op'>&gt;</span>,
}
<span class='comment'>// see codegen.rs for the explanation why impl Sync explicitly</span>
<span class='kw'>unsafe</span> <span class='kw'>impl</span> ::<span class='ident'>std</span>::<span class='ident'>marker</span>::<span class='ident'>Sync</span> <span class='kw'>for</span> <span class='ident'>ShareData</span> {}
<span class='kw'>impl</span> <span class='ident'>ShareData</span> {
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>new</span>() <span class='op'>-&gt;</span> <span class='ident'>ShareData</span> {
::<span class='ident'>std</span>::<span class='ident'>default</span>::<span class='ident'>Default</span>::<span class='ident'>default</span>()
}
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>default_instance</span>() <span class='op'>-&gt;</span> <span class='kw-2'>&amp;</span><span class='lifetime'>&#39;static</span> <span class='ident'>ShareData</span> {
<span class='kw'>static</span> <span class='kw-2'>mut</span> <span class='ident'>instance</span>: ::<span class='ident'>protobuf</span>::<span class='ident'>lazy</span>::<span class='ident'>Lazy</span><span class='op'>&lt;</span><span class='ident'>ShareData</span><span class='op'>&gt;</span> <span class='op'>=</span> ::<span class='ident'>protobuf</span>::<span class='ident'>lazy</span>::<span class='ident'>Lazy</span> {
<span class='ident'>lock</span>: ::<span class='ident'>protobuf</span>::<span class='ident'>lazy</span>::<span class='ident'>ONCE_INIT</span>,
<span class='ident'>ptr</span>: <span class='number'>0</span> <span class='kw'>as</span> <span class='op'>*</span><span class='kw'>const</span> <span class='ident'>ShareData</span>,
};
<span class='kw'>unsafe</span> {
<span class='ident'>instance</span>.<span class='ident'>get</span>(<span class='op'>||</span> {
<span class='ident'>ShareData</span> {
<span class='ident'>shamir_data</span>: ::<span class='ident'>protobuf</span>::<span class='ident'>SingularField</span>::<span class='ident'>none</span>(),
<span class='ident'>signature</span>: ::<span class='ident'>protobuf</span>::<span class='ident'>RepeatedField</span>::<span class='ident'>new</span>(),
<span class='ident'>proof</span>: ::<span class='ident'>protobuf</span>::<span class='ident'>SingularField</span>::<span class='ident'>none</span>(),
<span class='ident'>unknown_fields</span>: ::<span class='ident'>protobuf</span>::<span class='ident'>UnknownFields</span>::<span class='ident'>new</span>(),
<span class='ident'>cached_size</span>: ::<span class='ident'>std</span>::<span class='ident'>cell</span>::<span class='ident'>Cell</span>::<span class='ident'>new</span>(<span class='number'>0</span>),
}
})
}
}
<span class='comment'>// optional bytes shamir_data = 1;</span>
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>clear_shamir_data</span>(<span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> <span class='self'>self</span>) {
<span class='self'>self</span>.<span class='ident'>shamir_data</span>.<span class='ident'>clear</span>();
}
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>has_shamir_data</span>(<span class='kw-2'>&amp;</span><span class='self'>self</span>) <span class='op'>-&gt;</span> <span class='ident'>bool</span> {
<span class='self'>self</span>.<span class='ident'>shamir_data</span>.<span class='ident'>is_some</span>()
}
<span class='comment'>// Param is passed by value, moved</span>
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>set_shamir_data</span>(<span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>v</span>: ::<span class='ident'>std</span>::<span class='ident'>vec</span>::<span class='ident'>Vec</span><span class='op'>&lt;</span><span class='ident'>u8</span><span class='op'>&gt;</span>) {
<span class='self'>self</span>.<span class='ident'>shamir_data</span> <span class='op'>=</span> ::<span class='ident'>protobuf</span>::<span class='ident'>SingularField</span>::<span class='ident'>some</span>(<span class='ident'>v</span>);
}
<span class='comment'>// Mutable pointer to the field.</span>
<span class='comment'>// If field is not initialized, it is initialized with default value first.</span>
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>mut_shamir_data</span>(<span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> <span class='self'>self</span>) <span class='op'>-&gt;</span> <span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> ::<span class='ident'>std</span>::<span class='ident'>vec</span>::<span class='ident'>Vec</span><span class='op'>&lt;</span><span class='ident'>u8</span><span class='op'>&gt;</span> {
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>shamir_data</span>.<span class='ident'>is_none</span>() {
<span class='self'>self</span>.<span class='ident'>shamir_data</span>.<span class='ident'>set_default</span>();
};
<span class='self'>self</span>.<span class='ident'>shamir_data</span>.<span class='ident'>as_mut</span>().<span class='ident'>unwrap</span>()
}
<span class='comment'>// Take field</span>
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>take_shamir_data</span>(<span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> <span class='self'>self</span>) <span class='op'>-&gt;</span> ::<span class='ident'>std</span>::<span class='ident'>vec</span>::<span class='ident'>Vec</span><span class='op'>&lt;</span><span class='ident'>u8</span><span class='op'>&gt;</span> {
<span class='self'>self</span>.<span class='ident'>shamir_data</span>.<span class='ident'>take</span>().<span class='ident'>unwrap_or_else</span>(<span class='op'>||</span> ::<span class='ident'>std</span>::<span class='ident'>vec</span>::<span class='ident'>Vec</span>::<span class='ident'>new</span>())
}
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>get_shamir_data</span>(<span class='kw-2'>&amp;</span><span class='self'>self</span>) <span class='op'>-&gt;</span> <span class='kw-2'>&amp;</span>[<span class='ident'>u8</span>] {
<span class='kw'>match</span> <span class='self'>self</span>.<span class='ident'>shamir_data</span>.<span class='ident'>as_ref</span>() {
<span class='prelude-val'>Some</span>(<span class='ident'>v</span>) <span class='op'>=&gt;</span> <span class='kw-2'>&amp;</span><span class='ident'>v</span>,
<span class='prelude-val'>None</span> <span class='op'>=&gt;</span> <span class='kw-2'>&amp;</span>[],
}
}
<span class='comment'>// repeated bytes signature = 2;</span>
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>clear_signature</span>(<span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> <span class='self'>self</span>) {
<span class='self'>self</span>.<span class='ident'>signature</span>.<span class='ident'>clear</span>();
}
<span class='comment'>// Param is passed by value, moved</span>
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>set_signature</span>(<span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>v</span>: ::<span class='ident'>protobuf</span>::<span class='ident'>RepeatedField</span><span class='op'>&lt;</span>::<span class='ident'>std</span>::<span class='ident'>vec</span>::<span class='ident'>Vec</span><span class='op'>&lt;</span><span class='ident'>u8</span><span class='op'>&gt;&gt;</span>) {
<span class='self'>self</span>.<span class='ident'>signature</span> <span class='op'>=</span> <span class='ident'>v</span>;
}
<span class='comment'>// Mutable pointer to the field.</span>
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>mut_signature</span>(<span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> <span class='self'>self</span>) <span class='op'>-&gt;</span> <span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> ::<span class='ident'>protobuf</span>::<span class='ident'>RepeatedField</span><span class='op'>&lt;</span>::<span class='ident'>std</span>::<span class='ident'>vec</span>::<span class='ident'>Vec</span><span class='op'>&lt;</span><span class='ident'>u8</span><span class='op'>&gt;&gt;</span> {
<span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> <span class='self'>self</span>.<span class='ident'>signature</span>
}
<span class='comment'>// Take field</span>
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>take_signature</span>(<span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> <span class='self'>self</span>) <span class='op'>-&gt;</span> ::<span class='ident'>protobuf</span>::<span class='ident'>RepeatedField</span><span class='op'>&lt;</span>::<span class='ident'>std</span>::<span class='ident'>vec</span>::<span class='ident'>Vec</span><span class='op'>&lt;</span><span class='ident'>u8</span><span class='op'>&gt;&gt;</span> {
::<span class='ident'>std</span>::<span class='ident'>mem</span>::<span class='ident'>replace</span>(<span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> <span class='self'>self</span>.<span class='ident'>signature</span>, ::<span class='ident'>protobuf</span>::<span class='ident'>RepeatedField</span>::<span class='ident'>new</span>())
}
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>get_signature</span>(<span class='kw-2'>&amp;</span><span class='self'>self</span>) <span class='op'>-&gt;</span> <span class='kw-2'>&amp;</span>[::<span class='ident'>std</span>::<span class='ident'>vec</span>::<span class='ident'>Vec</span><span class='op'>&lt;</span><span class='ident'>u8</span><span class='op'>&gt;</span>] {
<span class='kw-2'>&amp;</span><span class='self'>self</span>.<span class='ident'>signature</span>
}
<span class='comment'>// optional bytes proof = 3;</span>
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>clear_proof</span>(<span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> <span class='self'>self</span>) {
<span class='self'>self</span>.<span class='ident'>proof</span>.<span class='ident'>clear</span>();
}
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>has_proof</span>(<span class='kw-2'>&amp;</span><span class='self'>self</span>) <span class='op'>-&gt;</span> <span class='ident'>bool</span> {
<span class='self'>self</span>.<span class='ident'>proof</span>.<span class='ident'>is_some</span>()
}
<span class='comment'>// Param is passed by value, moved</span>
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>set_proof</span>(<span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>v</span>: ::<span class='ident'>std</span>::<span class='ident'>vec</span>::<span class='ident'>Vec</span><span class='op'>&lt;</span><span class='ident'>u8</span><span class='op'>&gt;</span>) {
<span class='self'>self</span>.<span class='ident'>proof</span> <span class='op'>=</span> ::<span class='ident'>protobuf</span>::<span class='ident'>SingularField</span>::<span class='ident'>some</span>(<span class='ident'>v</span>);
}
<span class='comment'>// Mutable pointer to the field.</span>
<span class='comment'>// If field is not initialized, it is initialized with default value first.</span>
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>mut_proof</span>(<span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> <span class='self'>self</span>) <span class='op'>-&gt;</span> <span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> ::<span class='ident'>std</span>::<span class='ident'>vec</span>::<span class='ident'>Vec</span><span class='op'>&lt;</span><span class='ident'>u8</span><span class='op'>&gt;</span> {
<span class='kw'>if</span> <span class='self'>self</span>.<span class='ident'>proof</span>.<span class='ident'>is_none</span>() {
<span class='self'>self</span>.<span class='ident'>proof</span>.<span class='ident'>set_default</span>();
};
<span class='self'>self</span>.<span class='ident'>proof</span>.<span class='ident'>as_mut</span>().<span class='ident'>unwrap</span>()
}
<span class='comment'>// Take field</span>
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>take_proof</span>(<span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> <span class='self'>self</span>) <span class='op'>-&gt;</span> ::<span class='ident'>std</span>::<span class='ident'>vec</span>::<span class='ident'>Vec</span><span class='op'>&lt;</span><span class='ident'>u8</span><span class='op'>&gt;</span> {
<span class='self'>self</span>.<span class='ident'>proof</span>.<span class='ident'>take</span>().<span class='ident'>unwrap_or_else</span>(<span class='op'>||</span> ::<span class='ident'>std</span>::<span class='ident'>vec</span>::<span class='ident'>Vec</span>::<span class='ident'>new</span>())
}
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>get_proof</span>(<span class='kw-2'>&amp;</span><span class='self'>self</span>) <span class='op'>-&gt;</span> <span class='kw-2'>&amp;</span>[<span class='ident'>u8</span>] {
<span class='kw'>match</span> <span class='self'>self</span>.<span class='ident'>proof</span>.<span class='ident'>as_ref</span>() {
<span class='prelude-val'>Some</span>(<span class='ident'>v</span>) <span class='op'>=&gt;</span> <span class='kw-2'>&amp;</span><span class='ident'>v</span>,
<span class='prelude-val'>None</span> <span class='op'>=&gt;</span> <span class='kw-2'>&amp;</span>[],
}
}
}
<span class='kw'>impl</span> ::<span class='ident'>protobuf</span>::<span class='ident'>Message</span> <span class='kw'>for</span> <span class='ident'>ShareData</span> {
<span class='kw'>fn</span> <span class='ident'>is_initialized</span>(<span class='kw-2'>&amp;</span><span class='self'>self</span>) <span class='op'>-&gt;</span> <span class='ident'>bool</span> {
<span class='bool-val'>true</span>
}
<span class='kw'>fn</span> <span class='ident'>merge_from</span>(<span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> <span class='self'>self</span>, <span class='ident'>is</span>: <span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> ::<span class='ident'>protobuf</span>::<span class='ident'>CodedInputStream</span>) <span class='op'>-&gt;</span> ::<span class='ident'>protobuf</span>::<span class='ident'>ProtobufResult</span><span class='op'>&lt;</span>()<span class='op'>&gt;</span> {
<span class='kw'>while</span> <span class='op'>!</span><span class='macro'>try</span><span class='macro'>!</span>(<span class='ident'>is</span>.<span class='ident'>eof</span>()) {
<span class='kw'>let</span> (<span class='ident'>field_number</span>, <span class='ident'>wire_type</span>) <span class='op'>=</span> <span class='macro'>try</span><span class='macro'>!</span>(<span class='ident'>is</span>.<span class='ident'>read_tag_unpack</span>());
<span class='kw'>match</span> <span class='ident'>field_number</span> {
<span class='number'>1</span> <span class='op'>=&gt;</span> {
<span class='macro'>try</span><span class='macro'>!</span>(::<span class='ident'>protobuf</span>::<span class='ident'>rt</span>::<span class='ident'>read_singular_bytes_into</span>(<span class='ident'>wire_type</span>, <span class='ident'>is</span>, <span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> <span class='self'>self</span>.<span class='ident'>shamir_data</span>));
},
<span class='number'>2</span> <span class='op'>=&gt;</span> {
<span class='macro'>try</span><span class='macro'>!</span>(::<span class='ident'>protobuf</span>::<span class='ident'>rt</span>::<span class='ident'>read_repeated_bytes_into</span>(<span class='ident'>wire_type</span>, <span class='ident'>is</span>, <span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> <span class='self'>self</span>.<span class='ident'>signature</span>));
},
<span class='number'>3</span> <span class='op'>=&gt;</span> {
<span class='macro'>try</span><span class='macro'>!</span>(::<span class='ident'>protobuf</span>::<span class='ident'>rt</span>::<span class='ident'>read_singular_bytes_into</span>(<span class='ident'>wire_type</span>, <span class='ident'>is</span>, <span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> <span class='self'>self</span>.<span class='ident'>proof</span>));
},
_ <span class='op'>=&gt;</span> {
<span class='macro'>try</span><span class='macro'>!</span>(::<span class='ident'>protobuf</span>::<span class='ident'>rt</span>::<span class='ident'>read_unknown_or_skip_group</span>(<span class='ident'>field_number</span>, <span class='ident'>wire_type</span>, <span class='ident'>is</span>, <span class='self'>self</span>.<span class='ident'>mut_unknown_fields</span>()));
},
};
}
::<span class='ident'>std</span>::<span class='ident'>result</span>::<span class='prelude-ty'>Result</span>::<span class='prelude-val'>Ok</span>(())
}
<span class='comment'>// Compute sizes of nested messages</span>
<span class='attribute'>#[<span class='ident'>allow</span>(<span class='ident'>unused_variables</span>)]</span>
<span class='kw'>fn</span> <span class='ident'>compute_size</span>(<span class='kw-2'>&amp;</span><span class='self'>self</span>) <span class='op'>-&gt;</span> <span class='ident'>u32</span> {
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>my_size</span> <span class='op'>=</span> <span class='number'>0</span>;
<span class='kw'>for</span> <span class='ident'>value</span> <span class='kw'>in</span> <span class='kw-2'>&amp;</span><span class='self'>self</span>.<span class='ident'>shamir_data</span> {
<span class='ident'>my_size</span> <span class='op'>+=</span> ::<span class='ident'>protobuf</span>::<span class='ident'>rt</span>::<span class='ident'>bytes_size</span>(<span class='number'>1</span>, <span class='kw-2'>&amp;</span><span class='ident'>value</span>);
};
<span class='kw'>for</span> <span class='ident'>value</span> <span class='kw'>in</span> <span class='kw-2'>&amp;</span><span class='self'>self</span>.<span class='ident'>signature</span> {
<span class='ident'>my_size</span> <span class='op'>+=</span> ::<span class='ident'>protobuf</span>::<span class='ident'>rt</span>::<span class='ident'>bytes_size</span>(<span class='number'>2</span>, <span class='kw-2'>&amp;</span><span class='ident'>value</span>);
};
<span class='kw'>for</span> <span class='ident'>value</span> <span class='kw'>in</span> <span class='kw-2'>&amp;</span><span class='self'>self</span>.<span class='ident'>proof</span> {
<span class='ident'>my_size</span> <span class='op'>+=</span> ::<span class='ident'>protobuf</span>::<span class='ident'>rt</span>::<span class='ident'>bytes_size</span>(<span class='number'>3</span>, <span class='kw-2'>&amp;</span><span class='ident'>value</span>);
};
<span class='ident'>my_size</span> <span class='op'>+=</span> ::<span class='ident'>protobuf</span>::<span class='ident'>rt</span>::<span class='ident'>unknown_fields_size</span>(<span class='self'>self</span>.<span class='ident'>get_unknown_fields</span>());
<span class='self'>self</span>.<span class='ident'>cached_size</span>.<span class='ident'>set</span>(<span class='ident'>my_size</span>);
<span class='ident'>my_size</span>
}
<span class='kw'>fn</span> <span class='ident'>write_to_with_cached_sizes</span>(<span class='kw-2'>&amp;</span><span class='self'>self</span>, <span class='ident'>os</span>: <span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> ::<span class='ident'>protobuf</span>::<span class='ident'>CodedOutputStream</span>) <span class='op'>-&gt;</span> ::<span class='ident'>protobuf</span>::<span class='ident'>ProtobufResult</span><span class='op'>&lt;</span>()<span class='op'>&gt;</span> {
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>v</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>shamir_data</span>.<span class='ident'>as_ref</span>() {
<span class='macro'>try</span><span class='macro'>!</span>(<span class='ident'>os</span>.<span class='ident'>write_bytes</span>(<span class='number'>1</span>, <span class='kw-2'>&amp;</span><span class='ident'>v</span>));
};
<span class='kw'>for</span> <span class='ident'>v</span> <span class='kw'>in</span> <span class='kw-2'>&amp;</span><span class='self'>self</span>.<span class='ident'>signature</span> {
<span class='macro'>try</span><span class='macro'>!</span>(<span class='ident'>os</span>.<span class='ident'>write_bytes</span>(<span class='number'>2</span>, <span class='kw-2'>&amp;</span><span class='ident'>v</span>));
};
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>v</span>) <span class='op'>=</span> <span class='self'>self</span>.<span class='ident'>proof</span>.<span class='ident'>as_ref</span>() {
<span class='macro'>try</span><span class='macro'>!</span>(<span class='ident'>os</span>.<span class='ident'>write_bytes</span>(<span class='number'>3</span>, <span class='kw-2'>&amp;</span><span class='ident'>v</span>));
};
<span class='macro'>try</span><span class='macro'>!</span>(<span class='ident'>os</span>.<span class='ident'>write_unknown_fields</span>(<span class='self'>self</span>.<span class='ident'>get_unknown_fields</span>()));
::<span class='ident'>std</span>::<span class='ident'>result</span>::<span class='prelude-ty'>Result</span>::<span class='prelude-val'>Ok</span>(())
}
<span class='kw'>fn</span> <span class='ident'>get_cached_size</span>(<span class='kw-2'>&amp;</span><span class='self'>self</span>) <span class='op'>-&gt;</span> <span class='ident'>u32</span> {
<span class='self'>self</span>.<span class='ident'>cached_size</span>.<span class='ident'>get</span>()
}
<span class='kw'>fn</span> <span class='ident'>get_unknown_fields</span>(<span class='kw-2'>&amp;</span><span class='self'>self</span>) <span class='op'>-&gt;</span> <span class='kw-2'>&amp;</span>::<span class='ident'>protobuf</span>::<span class='ident'>UnknownFields</span> {
<span class='kw-2'>&amp;</span><span class='self'>self</span>.<span class='ident'>unknown_fields</span>
}
<span class='kw'>fn</span> <span class='ident'>mut_unknown_fields</span>(<span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> <span class='self'>self</span>) <span class='op'>-&gt;</span> <span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> ::<span class='ident'>protobuf</span>::<span class='ident'>UnknownFields</span> {
<span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> <span class='self'>self</span>.<span class='ident'>unknown_fields</span>
}
<span class='kw'>fn</span> <span class='ident'>type_id</span>(<span class='kw-2'>&amp;</span><span class='self'>self</span>) <span class='op'>-&gt;</span> ::<span class='ident'>std</span>::<span class='ident'>any</span>::<span class='ident'>TypeId</span> {
::<span class='ident'>std</span>::<span class='ident'>any</span>::<span class='ident'>TypeId</span>::<span class='ident'>of</span>::<span class='op'>&lt;</span><span class='ident'>ShareData</span><span class='op'>&gt;</span>()
}
<span class='kw'>fn</span> <span class='ident'>as_any</span>(<span class='kw-2'>&amp;</span><span class='self'>self</span>) <span class='op'>-&gt;</span> <span class='kw-2'>&amp;</span>::<span class='ident'>std</span>::<span class='ident'>any</span>::<span class='ident'>Any</span> {
<span class='self'>self</span> <span class='kw'>as</span> <span class='kw-2'>&amp;</span>::<span class='ident'>std</span>::<span class='ident'>any</span>::<span class='ident'>Any</span>
}
<span class='kw'>fn</span> <span class='ident'>descriptor</span>(<span class='kw-2'>&amp;</span><span class='self'>self</span>) <span class='op'>-&gt;</span> <span class='kw-2'>&amp;</span><span class='lifetime'>&#39;static</span> ::<span class='ident'>protobuf</span>::<span class='ident'>reflect</span>::<span class='ident'>MessageDescriptor</span> {
::<span class='ident'>protobuf</span>::<span class='ident'>MessageStatic</span>::<span class='ident'>descriptor_static</span>(<span class='prelude-val'>None</span>::<span class='op'>&lt;</span><span class='self'>Self</span><span class='op'>&gt;</span>)
}
}
<span class='kw'>impl</span> ::<span class='ident'>protobuf</span>::<span class='ident'>MessageStatic</span> <span class='kw'>for</span> <span class='ident'>ShareData</span> {
<span class='kw'>fn</span> <span class='ident'>new</span>() <span class='op'>-&gt;</span> <span class='ident'>ShareData</span> {
<span class='ident'>ShareData</span>::<span class='ident'>new</span>()
}
<span class='kw'>fn</span> <span class='ident'>descriptor_static</span>(_: ::<span class='ident'>std</span>::<span class='ident'>option</span>::<span class='prelude-ty'>Option</span><span class='op'>&lt;</span><span class='ident'>ShareData</span><span class='op'>&gt;</span>) <span class='op'>-&gt;</span> <span class='kw-2'>&amp;</span><span class='lifetime'>&#39;static</span> ::<span class='ident'>protobuf</span>::<span class='ident'>reflect</span>::<span class='ident'>MessageDescriptor</span> {
<span class='kw'>static</span> <span class='kw-2'>mut</span> <span class='ident'>descriptor</span>: ::<span class='ident'>protobuf</span>::<span class='ident'>lazy</span>::<span class='ident'>Lazy</span><span class='op'>&lt;</span>::<span class='ident'>protobuf</span>::<span class='ident'>reflect</span>::<span class='ident'>MessageDescriptor</span><span class='op'>&gt;</span> <span class='op'>=</span> ::<span class='ident'>protobuf</span>::<span class='ident'>lazy</span>::<span class='ident'>Lazy</span> {
<span class='ident'>lock</span>: ::<span class='ident'>protobuf</span>::<span class='ident'>lazy</span>::<span class='ident'>ONCE_INIT</span>,
<span class='ident'>ptr</span>: <span class='number'>0</span> <span class='kw'>as</span> <span class='op'>*</span><span class='kw'>const</span> ::<span class='ident'>protobuf</span>::<span class='ident'>reflect</span>::<span class='ident'>MessageDescriptor</span>,
};
<span class='kw'>unsafe</span> {
<span class='ident'>descriptor</span>.<span class='ident'>get</span>(<span class='op'>||</span> {
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>fields</span> <span class='op'>=</span> ::<span class='ident'>std</span>::<span class='ident'>vec</span>::<span class='ident'>Vec</span>::<span class='ident'>new</span>();
<span class='ident'>fields</span>.<span class='ident'>push</span>(::<span class='ident'>protobuf</span>::<span class='ident'>reflect</span>::<span class='ident'>accessor</span>::<span class='ident'>make_singular_bytes_accessor</span>(
<span class='string'>&quot;shamir_data&quot;</span>,
<span class='ident'>ShareData</span>::<span class='ident'>has_shamir_data</span>,
<span class='ident'>ShareData</span>::<span class='ident'>get_shamir_data</span>,
));
<span class='ident'>fields</span>.<span class='ident'>push</span>(::<span class='ident'>protobuf</span>::<span class='ident'>reflect</span>::<span class='ident'>accessor</span>::<span class='ident'>make_repeated_bytes_accessor</span>(
<span class='string'>&quot;signature&quot;</span>,
<span class='ident'>ShareData</span>::<span class='ident'>get_signature</span>,
));
<span class='ident'>fields</span>.<span class='ident'>push</span>(::<span class='ident'>protobuf</span>::<span class='ident'>reflect</span>::<span class='ident'>accessor</span>::<span class='ident'>make_singular_bytes_accessor</span>(
<span class='string'>&quot;proof&quot;</span>,
<span class='ident'>ShareData</span>::<span class='ident'>has_proof</span>,
<span class='ident'>ShareData</span>::<span class='ident'>get_proof</span>,
));
::<span class='ident'>protobuf</span>::<span class='ident'>reflect</span>::<span class='ident'>MessageDescriptor</span>::<span class='ident'>new</span>::<span class='op'>&lt;</span><span class='ident'>ShareData</span><span class='op'>&gt;</span>(
<span class='string'>&quot;ShareData&quot;</span>,
<span class='ident'>fields</span>,
<span class='ident'>file_descriptor_proto</span>()
)
})
}
}
}
<span class='kw'>impl</span> ::<span class='ident'>protobuf</span>::<span class='ident'>Clear</span> <span class='kw'>for</span> <span class='ident'>ShareData</span> {
<span class='kw'>fn</span> <span class='ident'>clear</span>(<span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> <span class='self'>self</span>) {
<span class='self'>self</span>.<span class='ident'>clear_shamir_data</span>();
<span class='self'>self</span>.<span class='ident'>clear_signature</span>();
<span class='self'>self</span>.<span class='ident'>clear_proof</span>();
<span class='self'>self</span>.<span class='ident'>unknown_fields</span>.<span class='ident'>clear</span>();
}
}
<span class='kw'>impl</span> ::<span class='ident'>std</span>::<span class='ident'>cmp</span>::<span class='ident'>PartialEq</span> <span class='kw'>for</span> <span class='ident'>ShareData</span> {
<span class='kw'>fn</span> <span class='ident'>eq</span>(<span class='kw-2'>&amp;</span><span class='self'>self</span>, <span class='ident'>other</span>: <span class='kw-2'>&amp;</span><span class='ident'>ShareData</span>) <span class='op'>-&gt;</span> <span class='ident'>bool</span> {
<span class='self'>self</span>.<span class='ident'>shamir_data</span> <span class='op'>==</span> <span class='ident'>other</span>.<span class='ident'>shamir_data</span> <span class='op'>&amp;&amp;</span>
<span class='self'>self</span>.<span class='ident'>signature</span> <span class='op'>==</span> <span class='ident'>other</span>.<span class='ident'>signature</span> <span class='op'>&amp;&amp;</span>
<span class='self'>self</span>.<span class='ident'>proof</span> <span class='op'>==</span> <span class='ident'>other</span>.<span class='ident'>proof</span> <span class='op'>&amp;&amp;</span>
<span class='self'>self</span>.<span class='ident'>unknown_fields</span> <span class='op'>==</span> <span class='ident'>other</span>.<span class='ident'>unknown_fields</span>
}
}
<span class='kw'>impl</span> ::<span class='ident'>std</span>::<span class='ident'>fmt</span>::<span class='ident'>Debug</span> <span class='kw'>for</span> <span class='ident'>ShareData</span> {
<span class='kw'>fn</span> <span class='ident'>fmt</span>(<span class='kw-2'>&amp;</span><span class='self'>self</span>, <span class='ident'>f</span>: <span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> ::<span class='ident'>std</span>::<span class='ident'>fmt</span>::<span class='ident'>Formatter</span>) <span class='op'>-&gt;</span> ::<span class='ident'>std</span>::<span class='ident'>fmt</span>::<span class='prelude-ty'>Result</span> {
::<span class='ident'>protobuf</span>::<span class='ident'>text_format</span>::<span class='ident'>fmt</span>(<span class='self'>self</span>, <span class='ident'>f</span>)
}
}
<span class='kw'>static</span> <span class='ident'>file_descriptor_proto_data</span>: <span class='kw-2'>&amp;</span><span class='lifetime'>&#39;static</span> [<span class='ident'>u8</span>] <span class='op'>=</span> <span class='kw-2'>&amp;</span>[
<span class='number'>0x0a</span>, <span class='number'>0x18</span>, <span class='number'>0x70</span>, <span class='number'>0x72</span>, <span class='number'>0x6f</span>, <span class='number'>0x74</span>, <span class='number'>0x6f</span>, <span class='number'>0x62</span>, <span class='number'>0x75</span>, <span class='number'>0x66</span>, <span class='number'>0x2f</span>, <span class='number'>0x53</span>, <span class='number'>0x68</span>, <span class='number'>0x61</span>, <span class='number'>0x72</span>, <span class='number'>0x65</span>,
<span class='number'>0x44</span>, <span class='number'>0x61</span>, <span class='number'>0x74</span>, <span class='number'>0x61</span>, <span class='number'>0x2e</span>, <span class='number'>0x70</span>, <span class='number'>0x72</span>, <span class='number'>0x6f</span>, <span class='number'>0x74</span>, <span class='number'>0x6f</span>, <span class='number'>0x22</span>, <span class='number'>0x60</span>, <span class='number'>0x0a</span>, <span class='number'>0x09</span>, <span class='number'>0x53</span>, <span class='number'>0x68</span>,
<span class='number'>0x61</span>, <span class='number'>0x72</span>, <span class='number'>0x65</span>, <span class='number'>0x44</span>, <span class='number'>0x61</span>, <span class='number'>0x74</span>, <span class='number'>0x61</span>, <span class='number'>0x12</span>, <span class='number'>0x1f</span>, <span class='number'>0x0a</span>, <span class='number'>0x0b</span>, <span class='number'>0x73</span>, <span class='number'>0x68</span>, <span class='number'>0x61</span>, <span class='number'>0x6d</span>, <span class='number'>0x69</span>,
<span class='number'>0x72</span>, <span class='number'>0x5f</span>, <span class='number'>0x64</span>, <span class='number'>0x61</span>, <span class='number'>0x74</span>, <span class='number'>0x61</span>, <span class='number'>0x18</span>, <span class='number'>0x01</span>, <span class='number'>0x20</span>, <span class='number'>0x01</span>, <span class='number'>0x28</span>, <span class='number'>0x0c</span>, <span class='number'>0x52</span>, <span class='number'>0x0a</span>, <span class='number'>0x73</span>, <span class='number'>0x68</span>,
<span class='number'>0x61</span>, <span class='number'>0x6d</span>, <span class='number'>0x69</span>, <span class='number'>0x72</span>, <span class='number'>0x44</span>, <span class='number'>0x61</span>, <span class='number'>0x74</span>, <span class='number'>0x61</span>, <span class='number'>0x12</span>, <span class='number'>0x1c</span>, <span class='number'>0x0a</span>, <span class='number'>0x09</span>, <span class='number'>0x73</span>, <span class='number'>0x69</span>, <span class='number'>0x67</span>, <span class='number'>0x6e</span>,
<span class='number'>0x61</span>, <span class='number'>0x74</span>, <span class='number'>0x75</span>, <span class='number'>0x72</span>, <span class='number'>0x65</span>, <span class='number'>0x18</span>, <span class='number'>0x02</span>, <span class='number'>0x20</span>, <span class='number'>0x03</span>, <span class='number'>0x28</span>, <span class='number'>0x0c</span>, <span class='number'>0x52</span>, <span class='number'>0x09</span>, <span class='number'>0x73</span>, <span class='number'>0x69</span>, <span class='number'>0x67</span>,
<span class='number'>0x6e</span>, <span class='number'>0x61</span>, <span class='number'>0x74</span>, <span class='number'>0x75</span>, <span class='number'>0x72</span>, <span class='number'>0x65</span>, <span class='number'>0x12</span>, <span class='number'>0x14</span>, <span class='number'>0x0a</span>, <span class='number'>0x05</span>, <span class='number'>0x70</span>, <span class='number'>0x72</span>, <span class='number'>0x6f</span>, <span class='number'>0x6f</span>, <span class='number'>0x66</span>, <span class='number'>0x18</span>,
<span class='number'>0x03</span>, <span class='number'>0x20</span>, <span class='number'>0x01</span>, <span class='number'>0x28</span>, <span class='number'>0x0c</span>, <span class='number'>0x52</span>, <span class='number'>0x05</span>, <span class='number'>0x70</span>, <span class='number'>0x72</span>, <span class='number'>0x6f</span>, <span class='number'>0x6f</span>, <span class='number'>0x66</span>, <span class='number'>0x4a</span>, <span class='number'>0xfb</span>, <span class='number'>0x01</span>, <span class='number'>0x0a</span>,
<span class='number'>0x06</span>, <span class='number'>0x12</span>, <span class='number'>0x04</span>, <span class='number'>0x00</span>, <span class='number'>0x00</span>, <span class='number'>0x06</span>, <span class='number'>0x01</span>, <span class='number'>0x0a</span>, <span class='number'>0x08</span>, <span class='number'>0x0a</span>, <span class='number'>0x01</span>, <span class='number'>0x0c</span>, <span class='number'>0x12</span>, <span class='number'>0x03</span>, <span class='number'>0x00</span>, <span class='number'>0x00</span>,
<span class='number'>0x12</span>, <span class='number'>0x0a</span>, <span class='number'>0x0a</span>, <span class='number'>0x0a</span>, <span class='number'>0x02</span>, <span class='number'>0x04</span>, <span class='number'>0x00</span>, <span class='number'>0x12</span>, <span class='number'>0x04</span>, <span class='number'>0x02</span>, <span class='number'>0x00</span>, <span class='number'>0x06</span>, <span class='number'>0x01</span>, <span class='number'>0x0a</span>, <span class='number'>0x0a</span>, <span class='number'>0x0a</span>,
<span class='number'>0x03</span>, <span class='number'>0x04</span>, <span class='number'>0x00</span>, <span class='number'>0x01</span>, <span class='number'>0x12</span>, <span class='number'>0x03</span>, <span class='number'>0x02</span>, <span class='number'>0x08</span>, <span class='number'>0x11</span>, <span class='number'>0x0a</span>, <span class='number'>0x0b</span>, <span class='number'>0x0a</span>, <span class='number'>0x04</span>, <span class='number'>0x04</span>, <span class='number'>0x00</span>, <span class='number'>0x02</span>,
<span class='number'>0x00</span>, <span class='number'>0x12</span>, <span class='number'>0x03</span>, <span class='number'>0x03</span>, <span class='number'>0x08</span>, <span class='number'>0x1e</span>, <span class='number'>0x0a</span>, <span class='number'>0x0d</span>, <span class='number'>0x0a</span>, <span class='number'>0x05</span>, <span class='number'>0x04</span>, <span class='number'>0x00</span>, <span class='number'>0x02</span>, <span class='number'>0x00</span>, <span class='number'>0x04</span>, <span class='number'>0x12</span>,
<span class='number'>0x04</span>, <span class='number'>0x03</span>, <span class='number'>0x08</span>, <span class='number'>0x02</span>, <span class='number'>0x13</span>, <span class='number'>0x0a</span>, <span class='number'>0x0c</span>, <span class='number'>0x0a</span>, <span class='number'>0x05</span>, <span class='number'>0x04</span>, <span class='number'>0x00</span>, <span class='number'>0x02</span>, <span class='number'>0x00</span>, <span class='number'>0x05</span>, <span class='number'>0x12</span>, <span class='number'>0x03</span>,
<span class='number'>0x03</span>, <span class='number'>0x08</span>, <span class='number'>0x0d</span>, <span class='number'>0x0a</span>, <span class='number'>0x0c</span>, <span class='number'>0x0a</span>, <span class='number'>0x05</span>, <span class='number'>0x04</span>, <span class='number'>0x00</span>, <span class='number'>0x02</span>, <span class='number'>0x00</span>, <span class='number'>0x01</span>, <span class='number'>0x12</span>, <span class='number'>0x03</span>, <span class='number'>0x03</span>, <span class='number'>0x0e</span>,
<span class='number'>0x19</span>, <span class='number'>0x0a</span>, <span class='number'>0x0c</span>, <span class='number'>0x0a</span>, <span class='number'>0x05</span>, <span class='number'>0x04</span>, <span class='number'>0x00</span>, <span class='number'>0x02</span>, <span class='number'>0x00</span>, <span class='number'>0x03</span>, <span class='number'>0x12</span>, <span class='number'>0x03</span>, <span class='number'>0x03</span>, <span class='number'>0x1c</span>, <span class='number'>0x1d</span>, <span class='number'>0x0a</span>,
<span class='number'>0x0b</span>, <span class='number'>0x0a</span>, <span class='number'>0x04</span>, <span class='number'>0x04</span>, <span class='number'>0x00</span>, <span class='number'>0x02</span>, <span class='number'>0x01</span>, <span class='number'>0x12</span>, <span class='number'>0x03</span>, <span class='number'>0x04</span>, <span class='number'>0x08</span>, <span class='number'>0x25</span>, <span class='number'>0x0a</span>, <span class='number'>0x0c</span>, <span class='number'>0x0a</span>, <span class='number'>0x05</span>,
<span class='number'>0x04</span>, <span class='number'>0x00</span>, <span class='number'>0x02</span>, <span class='number'>0x01</span>, <span class='number'>0x04</span>, <span class='number'>0x12</span>, <span class='number'>0x03</span>, <span class='number'>0x04</span>, <span class='number'>0x08</span>, <span class='number'>0x10</span>, <span class='number'>0x0a</span>, <span class='number'>0x0c</span>, <span class='number'>0x0a</span>, <span class='number'>0x05</span>, <span class='number'>0x04</span>, <span class='number'>0x00</span>,
<span class='number'>0x02</span>, <span class='number'>0x01</span>, <span class='number'>0x05</span>, <span class='number'>0x12</span>, <span class='number'>0x03</span>, <span class='number'>0x04</span>, <span class='number'>0x11</span>, <span class='number'>0x16</span>, <span class='number'>0x0a</span>, <span class='number'>0x0c</span>, <span class='number'>0x0a</span>, <span class='number'>0x05</span>, <span class='number'>0x04</span>, <span class='number'>0x00</span>, <span class='number'>0x02</span>, <span class='number'>0x01</span>,
<span class='number'>0x01</span>, <span class='number'>0x12</span>, <span class='number'>0x03</span>, <span class='number'>0x04</span>, <span class='number'>0x17</span>, <span class='number'>0x20</span>, <span class='number'>0x0a</span>, <span class='number'>0x0c</span>, <span class='number'>0x0a</span>, <span class='number'>0x05</span>, <span class='number'>0x04</span>, <span class='number'>0x00</span>, <span class='number'>0x02</span>, <span class='number'>0x01</span>, <span class='number'>0x03</span>, <span class='number'>0x12</span>,
<span class='number'>0x03</span>, <span class='number'>0x04</span>, <span class='number'>0x23</span>, <span class='number'>0x24</span>, <span class='number'>0x0a</span>, <span class='number'>0x0b</span>, <span class='number'>0x0a</span>, <span class='number'>0x04</span>, <span class='number'>0x04</span>, <span class='number'>0x00</span>, <span class='number'>0x02</span>, <span class='number'>0x02</span>, <span class='number'>0x12</span>, <span class='number'>0x03</span>, <span class='number'>0x05</span>, <span class='number'>0x08</span>,
<span class='number'>0x18</span>, <span class='number'>0x0a</span>, <span class='number'>0x0d</span>, <span class='number'>0x0a</span>, <span class='number'>0x05</span>, <span class='number'>0x04</span>, <span class='number'>0x00</span>, <span class='number'>0x02</span>, <span class='number'>0x02</span>, <span class='number'>0x04</span>, <span class='number'>0x12</span>, <span class='number'>0x04</span>, <span class='number'>0x05</span>, <span class='number'>0x08</span>, <span class='number'>0x04</span>, <span class='number'>0x25</span>,
<span class='number'>0x0a</span>, <span class='number'>0x0c</span>, <span class='number'>0x0a</span>, <span class='number'>0x05</span>, <span class='number'>0x04</span>, <span class='number'>0x00</span>, <span class='number'>0x02</span>, <span class='number'>0x02</span>, <span class='number'>0x05</span>, <span class='number'>0x12</span>, <span class='number'>0x03</span>, <span class='number'>0x05</span>, <span class='number'>0x08</span>, <span class='number'>0x0d</span>, <span class='number'>0x0a</span>, <span class='number'>0x0c</span>,
<span class='number'>0x0a</span>, <span class='number'>0x05</span>, <span class='number'>0x04</span>, <span class='number'>0x00</span>, <span class='number'>0x02</span>, <span class='number'>0x02</span>, <span class='number'>0x01</span>, <span class='number'>0x12</span>, <span class='number'>0x03</span>, <span class='number'>0x05</span>, <span class='number'>0x0e</span>, <span class='number'>0x13</span>, <span class='number'>0x0a</span>, <span class='number'>0x0c</span>, <span class='number'>0x0a</span>, <span class='number'>0x05</span>,
<span class='number'>0x04</span>, <span class='number'>0x00</span>, <span class='number'>0x02</span>, <span class='number'>0x02</span>, <span class='number'>0x03</span>, <span class='number'>0x12</span>, <span class='number'>0x03</span>, <span class='number'>0x05</span>, <span class='number'>0x16</span>, <span class='number'>0x17</span>, <span class='number'>0x62</span>, <span class='number'>0x06</span>, <span class='number'>0x70</span>, <span class='number'>0x72</span>, <span class='number'>0x6f</span>, <span class='number'>0x74</span>,
<span class='number'>0x6f</span>, <span class='number'>0x33</span>,
];
<span class='kw'>static</span> <span class='kw-2'>mut</span> <span class='ident'>file_descriptor_proto_lazy</span>: ::<span class='ident'>protobuf</span>::<span class='ident'>lazy</span>::<span class='ident'>Lazy</span><span class='op'>&lt;</span>::<span class='ident'>protobuf</span>::<span class='ident'>descriptor</span>::<span class='ident'>FileDescriptorProto</span><span class='op'>&gt;</span> <span class='op'>=</span> ::<span class='ident'>protobuf</span>::<span class='ident'>lazy</span>::<span class='ident'>Lazy</span> {
<span class='ident'>lock</span>: ::<span class='ident'>protobuf</span>::<span class='ident'>lazy</span>::<span class='ident'>ONCE_INIT</span>,
<span class='ident'>ptr</span>: <span class='number'>0</span> <span class='kw'>as</span> <span class='op'>*</span><span class='kw'>const</span> ::<span class='ident'>protobuf</span>::<span class='ident'>descriptor</span>::<span class='ident'>FileDescriptorProto</span>,
};
<span class='kw'>fn</span> <span class='ident'>parse_descriptor_proto</span>() <span class='op'>-&gt;</span> ::<span class='ident'>protobuf</span>::<span class='ident'>descriptor</span>::<span class='ident'>FileDescriptorProto</span> {
::<span class='ident'>protobuf</span>::<span class='ident'>parse_from_bytes</span>(<span class='ident'>file_descriptor_proto_data</span>).<span class='ident'>unwrap</span>()
}
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>file_descriptor_proto</span>() <span class='op'>-&gt;</span> <span class='kw-2'>&amp;</span><span class='lifetime'>&#39;static</span> ::<span class='ident'>protobuf</span>::<span class='ident'>descriptor</span>::<span class='ident'>FileDescriptorProto</span> {
<span class='kw'>unsafe</span> {
<span class='ident'>file_descriptor_proto_lazy</span>.<span class='ident'>get</span>(<span class='op'>||</span> {
<span class='ident'>parse_descriptor_proto</span>()
})
}
}
</pre>
</section>
<section id='search' class="content hidden"></section>
<section class="footer"></section>
<aside id="help" class="hidden">
<div>
<h1 class="hidden">Help</h1>
<div class="shortcuts">
<h2>Keyboard Shortcuts</h2>
<dl>
<dt>?</dt>
<dd>Show this help dialog</dd>
<dt>S</dt>
<dd>Focus the search field</dd>
<dt>&larrb;</dt>
<dd>Move up in search results</dd>
<dt>&rarrb;</dt>
<dd>Move down in search results</dd>
<dt>&#9166;</dt>
<dd>Go to active search result</dd>
<dt>+</dt>
<dd>Collapse/expand all sections</dd>
</dl>
</div>
<div class="infos">
<h2>Search Tricks</h2>
<p>
Prefix searches with a type followed by a colon (e.g.
<code>fn:</code>) to restrict the search to a given type.
</p>
<p>
Accepted types are: <code>fn</code>, <code>mod</code>,
<code>struct</code>, <code>enum</code>,
<code>trait</code>, <code>type</code>, <code>macro</code>,
and <code>const</code>.
</p>
<p>
Search functions by type signature (e.g.
<code>vec -> usize</code> or <code>* -> vec</code>)
</p>
</div>
</div>
</aside>
<script>
window.rootPath = "../../../";
window.currentCrate = "rusty_secrets";
window.playgroundUrl = "";
</script>
<script src="../../../jquery.js"></script>
<script src="../../../main.js"></script>
<script defer src="../../../search-index.js"></script>
</body>
</html>

View File

@ -0,0 +1,282 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="rustdoc">
<meta name="description" content="Source to the Rust file `src/share_format.rs`.">
<meta name="keywords" content="rust, rustlang, rust-lang">
<title>share_format.rs.html -- source</title>
<link rel="stylesheet" type="text/css" href="../../../rustdoc.css">
<link rel="stylesheet" type="text/css" href="../../../main.css">
</head>
<body class="rustdoc">
<!--[if lte IE 8]>
<div class="warning">
This old browser is unsupported and will most likely display funky
things.
</div>
<![endif]-->
<nav class="sidebar">
</nav>
<nav class="sub">
<form class="search-form js-only">
<div class="search-container">
<input class="search-input" name="search"
autocomplete="off"
placeholder="Click or press S to search, ? for more options…"
type="search">
</div>
</form>
</nav>
<section id='main' class="content source"><pre class="line-numbers"><span id="1"> 1</span>
<span id="2"> 2</span>
<span id="3"> 3</span>
<span id="4"> 4</span>
<span id="5"> 5</span>
<span id="6"> 6</span>
<span id="7"> 7</span>
<span id="8"> 8</span>
<span id="9"> 9</span>
<span id="10">10</span>
<span id="11">11</span>
<span id="12">12</span>
<span id="13">13</span>
<span id="14">14</span>
<span id="15">15</span>
<span id="16">16</span>
<span id="17">17</span>
<span id="18">18</span>
<span id="19">19</span>
<span id="20">20</span>
<span id="21">21</span>
<span id="22">22</span>
<span id="23">23</span>
<span id="24">24</span>
<span id="25">25</span>
<span id="26">26</span>
<span id="27">27</span>
<span id="28">28</span>
<span id="29">29</span>
<span id="30">30</span>
<span id="31">31</span>
<span id="32">32</span>
<span id="33">33</span>
<span id="34">34</span>
<span id="35">35</span>
<span id="36">36</span>
<span id="37">37</span>
<span id="38">38</span>
<span id="39">39</span>
<span id="40">40</span>
<span id="41">41</span>
<span id="42">42</span>
<span id="43">43</span>
<span id="44">44</span>
<span id="45">45</span>
<span id="46">46</span>
<span id="47">47</span>
<span id="48">48</span>
<span id="49">49</span>
<span id="50">50</span>
<span id="51">51</span>
<span id="52">52</span>
<span id="53">53</span>
<span id="54">54</span>
<span id="55">55</span>
<span id="56">56</span>
<span id="57">57</span>
<span id="58">58</span>
<span id="59">59</span>
<span id="60">60</span>
<span id="61">61</span>
<span id="62">62</span>
<span id="63">63</span>
<span id="64">64</span>
<span id="65">65</span>
<span id="66">66</span>
<span id="67">67</span>
<span id="68">68</span>
<span id="69">69</span>
<span id="70">70</span>
<span id="71">71</span>
<span id="72">72</span>
<span id="73">73</span>
<span id="74">74</span>
<span id="75">75</span>
<span id="76">76</span>
<span id="77">77</span>
<span id="78">78</span>
<span id="79">79</span>
<span id="80">80</span>
<span id="81">81</span>
<span id="82">82</span>
<span id="83">83</span>
<span id="84">84</span>
<span id="85">85</span>
<span id="86">86</span>
</pre><pre class='rust '>
<span class='kw'>use</span> <span class='ident'>custom_error</span>::{<span class='ident'>other_io_err</span>, <span class='ident'>pie2io</span>};
<span class='kw'>use</span> <span class='ident'>digest</span>;
<span class='kw'>use</span> <span class='ident'>merkle_sigs</span>::<span class='ident'>Proof</span>;
<span class='kw'>use</span> <span class='ident'>merkle_sigs</span>::<span class='ident'>PublicKey</span>;
<span class='kw'>use</span> <span class='ident'>protobuf</span>;
<span class='kw'>use</span> <span class='ident'>protobuf</span>::{<span class='ident'>Message</span>, <span class='ident'>RepeatedField</span>};
<span class='kw'>use</span> <span class='ident'>serialize</span>;
<span class='kw'>use</span> <span class='ident'>serialize</span>::<span class='ident'>base64</span>::{<span class='self'>self</span>, <span class='ident'>FromBase64</span>, <span class='ident'>ToBase64</span>};
<span class='kw'>use</span> <span class='ident'>share_data</span>::<span class='ident'>ShareData</span>;
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>io</span>;
<span class='kw'>fn</span> <span class='ident'>base64_config</span>() <span class='op'>-&gt;</span> <span class='ident'>serialize</span>::<span class='ident'>base64</span>::<span class='ident'>Config</span> {
<span class='ident'>base64</span>::<span class='ident'>Config</span> { <span class='ident'>pad</span>: <span class='bool-val'>false</span>, ..<span class='ident'>base64</span>::<span class='ident'>STANDARD</span> }
}
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>share_string_from</span>(<span class='ident'>share</span>: <span class='ident'>Vec</span><span class='op'>&lt;</span><span class='ident'>u8</span><span class='op'>&gt;</span>,
<span class='ident'>threshold</span>: <span class='ident'>u8</span>,
<span class='ident'>share_num</span>: <span class='ident'>u8</span>,
<span class='ident'>signature_pair</span>: <span class='prelude-ty'>Option</span><span class='op'>&lt;</span>(<span class='ident'>Vec</span><span class='op'>&lt;</span><span class='ident'>Vec</span><span class='op'>&lt;</span><span class='ident'>u8</span><span class='op'>&gt;&gt;</span>, <span class='ident'>Proof</span><span class='op'>&lt;</span><span class='ident'>PublicKey</span><span class='op'>&gt;</span>)<span class='op'>&gt;</span>)
<span class='op'>-&gt;</span> <span class='ident'>String</span> {
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>share_protobuf</span> <span class='op'>=</span> <span class='ident'>ShareData</span>::<span class='ident'>new</span>();
<span class='ident'>share_protobuf</span>.<span class='ident'>set_shamir_data</span>(<span class='ident'>share</span>);
<span class='kw'>if</span> <span class='ident'>signature_pair</span>.<span class='ident'>is_some</span>() {
<span class='kw'>let</span> (<span class='ident'>signature</span>, <span class='ident'>proof</span>) <span class='op'>=</span> <span class='ident'>signature_pair</span>.<span class='ident'>unwrap</span>();
<span class='ident'>share_protobuf</span>.<span class='ident'>set_signature</span>(<span class='ident'>RepeatedField</span>::<span class='ident'>from_vec</span>(<span class='ident'>signature</span>));
<span class='ident'>share_protobuf</span>.<span class='ident'>set_proof</span>(<span class='ident'>proof</span>.<span class='ident'>write_to_bytes</span>().<span class='ident'>unwrap</span>());
}
<span class='kw'>let</span> <span class='ident'>b64_share</span> <span class='op'>=</span> <span class='ident'>share_protobuf</span>.<span class='ident'>write_to_bytes</span>().<span class='ident'>unwrap</span>().<span class='ident'>to_base64</span>(<span class='ident'>base64_config</span>());
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;{}-{}-{}&quot;</span>, <span class='ident'>threshold</span>, <span class='ident'>share_num</span>, <span class='ident'>b64_share</span>)
}
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>share_from_string</span>
(<span class='ident'>s</span>: <span class='kw-2'>&amp;</span><span class='ident'>str</span>,
<span class='ident'>is_signed</span>: <span class='ident'>bool</span>)
<span class='op'>-&gt;</span> <span class='ident'>io</span>::<span class='prelude-ty'>Result</span><span class='op'>&lt;</span>(<span class='ident'>Vec</span><span class='op'>&lt;</span><span class='ident'>u8</span><span class='op'>&gt;</span>, <span class='ident'>u8</span>, <span class='ident'>u8</span>, <span class='prelude-ty'>Option</span><span class='op'>&lt;</span>(<span class='ident'>Vec</span><span class='op'>&lt;</span><span class='ident'>Vec</span><span class='op'>&lt;</span><span class='ident'>u8</span><span class='op'>&gt;&gt;</span>, <span class='ident'>Proof</span><span class='op'>&lt;</span><span class='ident'>PublicKey</span><span class='op'>&gt;</span>)<span class='op'>&gt;</span>)<span class='op'>&gt;</span> {
<span class='kw'>let</span> <span class='ident'>parts</span>: <span class='ident'>Vec</span><span class='op'>&lt;</span>_<span class='op'>&gt;</span> <span class='op'>=</span> <span class='ident'>s</span>.<span class='ident'>trim</span>().<span class='ident'>split</span>(<span class='string'>&#39;-&#39;</span>).<span class='ident'>collect</span>();
<span class='kw'>if</span> <span class='ident'>parts</span>.<span class='ident'>len</span>() <span class='op'>!=</span> <span class='number'>3</span> {
<span class='kw'>return</span> <span class='prelude-val'>Err</span>(<span class='ident'>other_io_err</span>(<span class='string'>&quot;Share parse error: Expected 3 parts separated by a minus sign&quot;</span>,
<span class='prelude-val'>None</span>));
}
<span class='kw'>let</span> (<span class='ident'>k</span>, <span class='ident'>n</span>, <span class='ident'>p3</span>) <span class='op'>=</span> {
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>iter</span> <span class='op'>=</span> <span class='ident'>parts</span>.<span class='ident'>into_iter</span>();
<span class='kw'>let</span> <span class='ident'>k</span> <span class='op'>=</span> <span class='macro'>try</span><span class='macro'>!</span>(<span class='ident'>iter</span>.<span class='ident'>next</span>().<span class='ident'>unwrap</span>().<span class='ident'>parse</span>::<span class='op'>&lt;</span><span class='ident'>u8</span><span class='op'>&gt;</span>().<span class='ident'>map_err</span>(<span class='ident'>pie2io</span>));
<span class='kw'>let</span> <span class='ident'>n</span> <span class='op'>=</span> <span class='macro'>try</span><span class='macro'>!</span>(<span class='ident'>iter</span>.<span class='ident'>next</span>().<span class='ident'>unwrap</span>().<span class='ident'>parse</span>::<span class='op'>&lt;</span><span class='ident'>u8</span><span class='op'>&gt;</span>().<span class='ident'>map_err</span>(<span class='ident'>pie2io</span>));
<span class='kw'>let</span> <span class='ident'>p3</span> <span class='op'>=</span> <span class='ident'>iter</span>.<span class='ident'>next</span>().<span class='ident'>unwrap</span>();
(<span class='ident'>k</span>, <span class='ident'>n</span>, <span class='ident'>p3</span>)
};
<span class='kw'>if</span> <span class='ident'>k</span> <span class='op'>&lt;</span> <span class='number'>1</span> <span class='op'>||</span> <span class='ident'>n</span> <span class='op'>&lt;</span> <span class='number'>1</span> {
<span class='kw'>return</span> <span class='prelude-val'>Err</span>(<span class='ident'>other_io_err</span>(<span class='string'>&quot;Share parse error: Illegal K,N parameters&quot;</span>, <span class='prelude-val'>None</span>));
}
<span class='kw'>let</span> <span class='ident'>raw_data</span> <span class='op'>=</span> <span class='macro'>try</span><span class='macro'>!</span>(<span class='ident'>p3</span>.<span class='ident'>from_base64</span>().<span class='ident'>map_err</span>(<span class='op'>|</span>_<span class='op'>|</span> {
<span class='ident'>other_io_err</span>(<span class='string'>&quot;Share parse error: Base64 decoding of data block failed&quot;</span>,
<span class='prelude-val'>None</span>)
}));
<span class='kw'>let</span> <span class='ident'>protobuf_data</span> <span class='op'>=</span> <span class='macro'>try</span><span class='macro'>!</span>(<span class='ident'>protobuf</span>::<span class='ident'>parse_from_bytes</span>::<span class='op'>&lt;</span><span class='ident'>ShareData</span><span class='op'>&gt;</span>(<span class='ident'>raw_data</span>.<span class='ident'>as_slice</span>())
.<span class='ident'>map_err</span>(<span class='op'>|</span>_<span class='op'>|</span> <span class='ident'>other_io_err</span>(<span class='string'>&quot;Share parse error: Protobuffer could not be decoded.&quot;</span>, <span class='prelude-val'>None</span>)));
<span class='kw'>let</span> <span class='ident'>share</span> <span class='op'>=</span> <span class='ident'>Vec</span>::<span class='ident'>from</span>(<span class='ident'>protobuf_data</span>.<span class='ident'>get_shamir_data</span>());
<span class='kw'>if</span> <span class='ident'>is_signed</span> {
<span class='kw'>let</span> <span class='ident'>p</span> <span class='op'>=</span> <span class='ident'>Proof</span>::<span class='ident'>parse_from_bytes</span>(<span class='ident'>protobuf_data</span>.<span class='ident'>get_proof</span>(), <span class='ident'>digest</span>).<span class='ident'>unwrap</span>().<span class='ident'>unwrap</span>();
<span class='kw'>let</span> <span class='ident'>proof</span> <span class='op'>=</span> <span class='ident'>Proof</span> {
<span class='ident'>algorithm</span>: <span class='ident'>digest</span>,
<span class='ident'>lemma</span>: <span class='ident'>p</span>.<span class='ident'>lemma</span>,
<span class='ident'>root_hash</span>: <span class='ident'>p</span>.<span class='ident'>root_hash</span>,
<span class='ident'>value</span>: <span class='ident'>PublicKey</span>::<span class='ident'>from_vec</span>(<span class='ident'>p</span>.<span class='ident'>value</span>, <span class='ident'>digest</span>).<span class='ident'>unwrap</span>(),
};
<span class='kw'>let</span> <span class='ident'>signature</span> <span class='op'>=</span> <span class='ident'>protobuf_data</span>.<span class='ident'>get_signature</span>();
<span class='prelude-val'>Ok</span>((<span class='ident'>share</span>, <span class='ident'>k</span>, <span class='ident'>n</span>, <span class='prelude-val'>Some</span>((<span class='ident'>Vec</span>::<span class='ident'>from</span>(<span class='ident'>signature</span>), <span class='ident'>proof</span>))))
} <span class='kw'>else</span> {
<span class='prelude-val'>Ok</span>((<span class='ident'>share</span>, <span class='ident'>k</span>, <span class='ident'>n</span>, <span class='prelude-val'>None</span>))
}
}
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>format_share_for_signing</span>(<span class='ident'>k</span>: <span class='ident'>u8</span>, <span class='ident'>i</span>: <span class='ident'>u8</span>, <span class='ident'>data</span>: <span class='kw-2'>&amp;</span>[<span class='ident'>u8</span>]) <span class='op'>-&gt;</span> <span class='ident'>Vec</span><span class='op'>&lt;</span><span class='ident'>u8</span><span class='op'>&gt;</span> {
<span class='macro'>format</span><span class='macro'>!</span>(<span class='string'>&quot;{}-{}-{}&quot;</span>, <span class='ident'>k</span>, <span class='ident'>i</span>, <span class='ident'>data</span>.<span class='ident'>to_base64</span>(<span class='ident'>base64_config</span>())).<span class='ident'>into_bytes</span>()
}
</pre>
</section>
<section id='search' class="content hidden"></section>
<section class="footer"></section>
<aside id="help" class="hidden">
<div>
<h1 class="hidden">Help</h1>
<div class="shortcuts">
<h2>Keyboard Shortcuts</h2>
<dl>
<dt>?</dt>
<dd>Show this help dialog</dd>
<dt>S</dt>
<dd>Focus the search field</dd>
<dt>&larrb;</dt>
<dd>Move up in search results</dd>
<dt>&rarrb;</dt>
<dd>Move down in search results</dd>
<dt>&#9166;</dt>
<dd>Go to active search result</dd>
<dt>+</dt>
<dd>Collapse/expand all sections</dd>
</dl>
</div>
<div class="infos">
<h2>Search Tricks</h2>
<p>
Prefix searches with a type followed by a colon (e.g.
<code>fn:</code>) to restrict the search to a given type.
</p>
<p>
Accepted types are: <code>fn</code>, <code>mod</code>,
<code>struct</code>, <code>enum</code>,
<code>trait</code>, <code>type</code>, <code>macro</code>,
and <code>const</code>.
</p>
<p>
Search functions by type signature (e.g.
<code>vec -> usize</code> or <code>* -> vec</code>)
</p>
</div>
</div>
</aside>
<script>
window.rootPath = "../../../";
window.currentCrate = "rusty_secrets";
window.playgroundUrl = "";
</script>
<script src="../../../jquery.js"></script>
<script src="../../../main.js"></script>
<script defer src="../../../search-index.js"></script>
</body>
</html>

View File

@ -0,0 +1,362 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="rustdoc">
<meta name="description" content="Source to the Rust file `src/sss.rs`.">
<meta name="keywords" content="rust, rustlang, rust-lang">
<title>sss.rs.html -- source</title>
<link rel="stylesheet" type="text/css" href="../../../rustdoc.css">
<link rel="stylesheet" type="text/css" href="../../../main.css">
</head>
<body class="rustdoc">
<!--[if lte IE 8]>
<div class="warning">
This old browser is unsupported and will most likely display funky
things.
</div>
<![endif]-->
<nav class="sidebar">
</nav>
<nav class="sub">
<form class="search-form js-only">
<div class="search-container">
<input class="search-input" name="search"
autocomplete="off"
placeholder="Click or press S to search, ? for more options…"
type="search">
</div>
</form>
</nav>
<section id='main' class="content source"><pre class="line-numbers"><span id="1"> 1</span>
<span id="2"> 2</span>
<span id="3"> 3</span>
<span id="4"> 4</span>
<span id="5"> 5</span>
<span id="6"> 6</span>
<span id="7"> 7</span>
<span id="8"> 8</span>
<span id="9"> 9</span>
<span id="10"> 10</span>
<span id="11"> 11</span>
<span id="12"> 12</span>
<span id="13"> 13</span>
<span id="14"> 14</span>
<span id="15"> 15</span>
<span id="16"> 16</span>
<span id="17"> 17</span>
<span id="18"> 18</span>
<span id="19"> 19</span>
<span id="20"> 20</span>
<span id="21"> 21</span>
<span id="22"> 22</span>
<span id="23"> 23</span>
<span id="24"> 24</span>
<span id="25"> 25</span>
<span id="26"> 26</span>
<span id="27"> 27</span>
<span id="28"> 28</span>
<span id="29"> 29</span>
<span id="30"> 30</span>
<span id="31"> 31</span>
<span id="32"> 32</span>
<span id="33"> 33</span>
<span id="34"> 34</span>
<span id="35"> 35</span>
<span id="36"> 36</span>
<span id="37"> 37</span>
<span id="38"> 38</span>
<span id="39"> 39</span>
<span id="40"> 40</span>
<span id="41"> 41</span>
<span id="42"> 42</span>
<span id="43"> 43</span>
<span id="44"> 44</span>
<span id="45"> 45</span>
<span id="46"> 46</span>
<span id="47"> 47</span>
<span id="48"> 48</span>
<span id="49"> 49</span>
<span id="50"> 50</span>
<span id="51"> 51</span>
<span id="52"> 52</span>
<span id="53"> 53</span>
<span id="54"> 54</span>
<span id="55"> 55</span>
<span id="56"> 56</span>
<span id="57"> 57</span>
<span id="58"> 58</span>
<span id="59"> 59</span>
<span id="60"> 60</span>
<span id="61"> 61</span>
<span id="62"> 62</span>
<span id="63"> 63</span>
<span id="64"> 64</span>
<span id="65"> 65</span>
<span id="66"> 66</span>
<span id="67"> 67</span>
<span id="68"> 68</span>
<span id="69"> 69</span>
<span id="70"> 70</span>
<span id="71"> 71</span>
<span id="72"> 72</span>
<span id="73"> 73</span>
<span id="74"> 74</span>
<span id="75"> 75</span>
<span id="76"> 76</span>
<span id="77"> 77</span>
<span id="78"> 78</span>
<span id="79"> 79</span>
<span id="80"> 80</span>
<span id="81"> 81</span>
<span id="82"> 82</span>
<span id="83"> 83</span>
<span id="84"> 84</span>
<span id="85"> 85</span>
<span id="86"> 86</span>
<span id="87"> 87</span>
<span id="88"> 88</span>
<span id="89"> 89</span>
<span id="90"> 90</span>
<span id="91"> 91</span>
<span id="92"> 92</span>
<span id="93"> 93</span>
<span id="94"> 94</span>
<span id="95"> 95</span>
<span id="96"> 96</span>
<span id="97"> 97</span>
<span id="98"> 98</span>
<span id="99"> 99</span>
<span id="100">100</span>
<span id="101">101</span>
<span id="102">102</span>
<span id="103">103</span>
<span id="104">104</span>
<span id="105">105</span>
<span id="106">106</span>
<span id="107">107</span>
<span id="108">108</span>
<span id="109">109</span>
<span id="110">110</span>
<span id="111">111</span>
<span id="112">112</span>
<span id="113">113</span>
<span id="114">114</span>
<span id="115">115</span>
<span id="116">116</span>
<span id="117">117</span>
<span id="118">118</span>
<span id="119">119</span>
<span id="120">120</span>
<span id="121">121</span>
<span id="122">122</span>
<span id="123">123</span>
<span id="124">124</span>
<span id="125">125</span>
<span id="126">126</span>
</pre><pre class='rust '>
<span class='kw'>use</span> <span class='ident'>custom_error</span>::<span class='ident'>other_io_err</span>;
<span class='kw'>use</span> <span class='ident'>digest</span>;
<span class='kw'>use</span> <span class='ident'>interpolation</span>::{<span class='ident'>encode</span>, <span class='ident'>lagrange_interpolate</span>};
<span class='kw'>use</span> <span class='ident'>merkle_sigs</span>::<span class='ident'>sign_data_vec</span>;
<span class='kw'>use</span> <span class='ident'>rand</span>::{<span class='ident'>OsRng</span>, <span class='ident'>Rng</span>};
<span class='kw'>use</span> <span class='ident'>share_format</span>::<span class='ident'>format_share_for_signing</span>;
<span class='kw'>use</span> <span class='ident'>share_format</span>::<span class='ident'>share_string_from</span>;
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>io</span>;
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>iter</span>::<span class='ident'>repeat</span>;
<span class='kw'>use</span> <span class='ident'>validation</span>::<span class='ident'>process_and_validate_shares</span>;
<span class='kw'>fn</span> <span class='ident'>new_vec</span><span class='op'>&lt;</span><span class='ident'>T</span>: <span class='ident'>Clone</span><span class='op'>&gt;</span>(<span class='ident'>n</span>: <span class='ident'>usize</span>, <span class='ident'>x</span>: <span class='ident'>T</span>) <span class='op'>-&gt;</span> <span class='ident'>Vec</span><span class='op'>&lt;</span><span class='ident'>T</span><span class='op'>&gt;</span> {
<span class='ident'>repeat</span>(<span class='ident'>x</span>).<span class='ident'>take</span>(<span class='ident'>n</span>).<span class='ident'>collect</span>()
}
<span class='doccomment'>/// Performs threshold k-out-of-n Shamir secret sharing.</span>
<span class='doccomment'>///</span>
<span class='doccomment'>/// # Examples</span>
<span class='doccomment'>///</span>
<span class='doccomment'>/// ```</span>
<span class='doccomment'>/// use rusty_secrets::generate_shares;</span>
<span class='doccomment'>/// let secret = &quot;These programs were never about terrorism: theyre about economic spying,</span>
<span class='doccomment'>/// social control, and diplomatic manipulation. Theyre about power.&quot;.to_string();</span>
<span class='doccomment'>///</span>
<span class='doccomment'>/// match generate_shares(7, 10, &amp;secret.into_bytes(), true){</span>
<span class='doccomment'>/// Ok(shares) =&gt; {</span>
<span class='doccomment'>/// // Do something with the shares</span>
<span class='doccomment'>/// },</span>
<span class='doccomment'>/// Err(_) =&gt; {}// Deal with error}</span>
<span class='doccomment'>/// }</span>
<span class='doccomment'>/// ```</span>
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>generate_shares</span>(<span class='ident'>k</span>: <span class='ident'>u8</span>, <span class='ident'>n</span>: <span class='ident'>u8</span>, <span class='ident'>secret</span>: <span class='kw-2'>&amp;</span>[<span class='ident'>u8</span>], <span class='ident'>sign_shares</span>: <span class='ident'>bool</span>) <span class='op'>-&gt;</span> <span class='ident'>io</span>::<span class='prelude-ty'>Result</span><span class='op'>&lt;</span><span class='ident'>Vec</span><span class='op'>&lt;</span><span class='ident'>String</span><span class='op'>&gt;&gt;</span> {
<span class='kw'>if</span> <span class='ident'>k</span> <span class='op'>&gt;</span> <span class='ident'>n</span> {
<span class='kw'>return</span> <span class='prelude-val'>Err</span>(<span class='ident'>other_io_err</span>(<span class='string'>&quot;Threshold K can not be larger than N&quot;</span>, <span class='prelude-val'>None</span>));
}
<span class='kw'>let</span> <span class='ident'>shares</span> <span class='op'>=</span> <span class='macro'>try</span><span class='macro'>!</span>(<span class='ident'>secret_share</span>(<span class='kw-2'>&amp;</span><span class='op'>*</span><span class='ident'>secret</span>, <span class='ident'>k</span>, <span class='ident'>n</span>));
<span class='kw'>let</span> <span class='ident'>signatures</span> <span class='op'>=</span> <span class='kw'>if</span> <span class='ident'>sign_shares</span> {
<span class='kw'>let</span> <span class='ident'>shares_to_sign</span> <span class='op'>=</span> <span class='ident'>shares</span>.<span class='ident'>iter</span>()
.<span class='ident'>enumerate</span>()
.<span class='ident'>map</span>(<span class='op'>|</span>(<span class='ident'>i</span>, <span class='ident'>x</span>)<span class='op'>|</span> <span class='ident'>format_share_for_signing</span>(<span class='ident'>k</span>, (<span class='ident'>i</span> <span class='op'>+</span> <span class='number'>1</span>) <span class='kw'>as</span> <span class='ident'>u8</span>, <span class='ident'>x</span>))
.<span class='ident'>collect</span>::<span class='op'>&lt;</span><span class='ident'>Vec</span><span class='op'>&lt;</span>_<span class='op'>&gt;&gt;</span>();
<span class='kw'>let</span> <span class='ident'>sign</span> <span class='op'>=</span> <span class='ident'>sign_data_vec</span>(<span class='kw-2'>&amp;</span><span class='ident'>shares_to_sign</span>, <span class='ident'>digest</span>)
.<span class='ident'>unwrap</span>()
.<span class='ident'>into_iter</span>()
.<span class='ident'>map</span>(<span class='prelude-val'>Some</span>)
.<span class='ident'>collect</span>::<span class='op'>&lt;</span><span class='ident'>Vec</span><span class='op'>&lt;</span>_<span class='op'>&gt;&gt;</span>();
<span class='prelude-val'>Some</span>(<span class='ident'>sign</span>)
} <span class='kw'>else</span> {
<span class='prelude-val'>None</span>
};
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>result</span> <span class='op'>=</span> <span class='ident'>Vec</span>::<span class='ident'>with_capacity</span>(<span class='ident'>n</span> <span class='kw'>as</span> <span class='ident'>usize</span>);
<span class='kw'>for</span> ((<span class='ident'>index</span>, <span class='ident'>share</span>), <span class='ident'>signature_pair</span>) <span class='kw'>in</span>
<span class='ident'>shares</span>.<span class='ident'>into_iter</span>()
.<span class='ident'>enumerate</span>()
.<span class='ident'>zip</span>(<span class='ident'>signatures</span>.<span class='ident'>unwrap_or_else</span>(<span class='op'>||</span> <span class='macro'>vec</span><span class='macro'>!</span>[<span class='prelude-val'>None</span>; <span class='ident'>n</span> <span class='kw'>as</span> <span class='ident'>usize</span>]).<span class='ident'>into_iter</span>()) {
<span class='kw'>let</span> <span class='ident'>share_string</span> <span class='op'>=</span> <span class='ident'>share_string_from</span>(<span class='ident'>share</span>, <span class='ident'>k</span>, (<span class='ident'>index</span> <span class='op'>+</span> <span class='number'>1</span>) <span class='kw'>as</span> <span class='ident'>u8</span>, <span class='ident'>signature_pair</span>);
<span class='ident'>result</span>.<span class='ident'>push</span>(<span class='ident'>share_string</span>);
}
<span class='prelude-val'>Ok</span>(<span class='ident'>result</span>)
}
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>secret_share</span>(<span class='ident'>src</span>: <span class='kw-2'>&amp;</span>[<span class='ident'>u8</span>], <span class='ident'>k</span>: <span class='ident'>u8</span>, <span class='ident'>n</span>: <span class='ident'>u8</span>) <span class='op'>-&gt;</span> <span class='ident'>io</span>::<span class='prelude-ty'>Result</span><span class='op'>&lt;</span><span class='ident'>Vec</span><span class='op'>&lt;</span><span class='ident'>Vec</span><span class='op'>&lt;</span><span class='ident'>u8</span><span class='op'>&gt;&gt;</span><span class='op'>&gt;</span> {
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>result</span> <span class='op'>=</span> <span class='ident'>Vec</span>::<span class='ident'>with_capacity</span>(<span class='ident'>n</span> <span class='kw'>as</span> <span class='ident'>usize</span>);
<span class='kw'>for</span> _ <span class='kw'>in</span> <span class='number'>0</span>..(<span class='ident'>n</span> <span class='kw'>as</span> <span class='ident'>usize</span>) {
<span class='ident'>result</span>.<span class='ident'>push</span>(<span class='ident'>new_vec</span>(<span class='ident'>src</span>.<span class='ident'>len</span>(), <span class='number'>0u8</span>));
}
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>col_in</span> <span class='op'>=</span> <span class='ident'>new_vec</span>(<span class='ident'>k</span> <span class='kw'>as</span> <span class='ident'>usize</span>, <span class='number'>0u8</span>);
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>col_out</span> <span class='op'>=</span> <span class='ident'>Vec</span>::<span class='ident'>with_capacity</span>(<span class='ident'>n</span> <span class='kw'>as</span> <span class='ident'>usize</span>);
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>osrng</span> <span class='op'>=</span> <span class='macro'>try</span><span class='macro'>!</span>(<span class='ident'>OsRng</span>::<span class='ident'>new</span>());
<span class='kw'>for</span> (<span class='ident'>c</span>, <span class='kw-2'>&amp;</span><span class='ident'>s</span>) <span class='kw'>in</span> <span class='ident'>src</span>.<span class='ident'>iter</span>().<span class='ident'>enumerate</span>() {
<span class='ident'>col_in</span>[<span class='number'>0</span>] <span class='op'>=</span> <span class='ident'>s</span>;
<span class='ident'>osrng</span>.<span class='ident'>fill_bytes</span>(<span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> <span class='ident'>col_in</span>[<span class='number'>1</span>..]);
<span class='ident'>col_out</span>.<span class='ident'>clear</span>();
<span class='macro'>try</span><span class='macro'>!</span>(<span class='ident'>encode</span>(<span class='kw-2'>&amp;</span><span class='op'>*</span><span class='ident'>col_in</span>, <span class='ident'>n</span>, <span class='kw-2'>&amp;</span><span class='kw-2'>mut</span> <span class='ident'>col_out</span>));
<span class='kw'>for</span> (<span class='kw-2'>&amp;</span><span class='ident'>y</span>, <span class='ident'>share</span>) <span class='kw'>in</span> <span class='ident'>col_out</span>.<span class='ident'>iter</span>().<span class='ident'>zip</span>(<span class='ident'>result</span>.<span class='ident'>iter_mut</span>()) {
<span class='ident'>share</span>[<span class='ident'>c</span>] <span class='op'>=</span> <span class='ident'>y</span>;
}
}
<span class='prelude-val'>Ok</span>(<span class='ident'>result</span>)
}
<span class='doccomment'>/// Recovers the secret from a k-out-of-n Shamir secret sharing.</span>
<span class='doccomment'>///</span>
<span class='doccomment'>/// At least `k` distinct shares need to be provided to recover the share.</span>
<span class='doccomment'>///</span>
<span class='doccomment'>/// # Examples</span>
<span class='doccomment'>///</span>
<span class='doccomment'>/// ```</span>
<span class='doccomment'>/// use rusty_secrets::recover_secret;</span>
<span class='doccomment'>/// let share1 = &quot;2-1-Cha7s14Q/mSwWko0ittr+/Uf79RHQMIP&quot;.to_string();</span>
<span class='doccomment'>/// let share2 = &quot;2-4-ChaydsUJDypD9ZWxwvIICh/cmZvzusOF&quot;.to_string();</span>
<span class='doccomment'>/// let shares = vec![share1, share2];</span>
<span class='doccomment'>///</span>
<span class='doccomment'>/// match recover_secret(shares, false) {</span>
<span class='doccomment'>/// Ok(secret) =&gt; {</span>
<span class='doccomment'>/// // Do something with the secret</span>
<span class='doccomment'>/// },</span>
<span class='doccomment'>/// Err(e) =&gt; {</span>
<span class='doccomment'>/// // Deal with the error</span>
<span class='doccomment'>/// }</span>
<span class='doccomment'>/// }</span>
<span class='doccomment'>/// ```</span>
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>recover_secret</span>(<span class='ident'>shares</span>: <span class='ident'>Vec</span><span class='op'>&lt;</span><span class='ident'>String</span><span class='op'>&gt;</span>, <span class='ident'>verify_signatures</span>: <span class='ident'>bool</span>) <span class='op'>-&gt;</span> <span class='ident'>io</span>::<span class='prelude-ty'>Result</span><span class='op'>&lt;</span><span class='ident'>Vec</span><span class='op'>&lt;</span><span class='ident'>u8</span><span class='op'>&gt;&gt;</span> {
<span class='kw'>let</span> (<span class='ident'>k</span>, <span class='ident'>shares</span>) <span class='op'>=</span> <span class='macro'>try</span><span class='macro'>!</span>(<span class='ident'>process_and_validate_shares</span>(<span class='ident'>shares</span>, <span class='ident'>verify_signatures</span>));
<span class='kw'>let</span> <span class='ident'>slen</span> <span class='op'>=</span> <span class='ident'>shares</span>[<span class='number'>0</span>].<span class='number'>1</span>.<span class='ident'>len</span>();
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>col_in</span> <span class='op'>=</span> <span class='ident'>Vec</span>::<span class='ident'>with_capacity</span>(<span class='ident'>k</span> <span class='kw'>as</span> <span class='ident'>usize</span>);
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>secret</span> <span class='op'>=</span> <span class='ident'>Vec</span>::<span class='ident'>with_capacity</span>(<span class='ident'>slen</span>);
<span class='kw'>for</span> <span class='ident'>byteindex</span> <span class='kw'>in</span> <span class='number'>0</span>..<span class='ident'>slen</span> {
<span class='ident'>col_in</span>.<span class='ident'>clear</span>();
<span class='kw'>for</span> <span class='ident'>s</span> <span class='kw'>in</span> <span class='ident'>shares</span>.<span class='ident'>iter</span>().<span class='ident'>take</span>(<span class='ident'>k</span> <span class='kw'>as</span> <span class='ident'>usize</span>) {
<span class='ident'>col_in</span>.<span class='ident'>push</span>((<span class='ident'>s</span>.<span class='number'>0</span>, <span class='ident'>s</span>.<span class='number'>1</span>[<span class='ident'>byteindex</span>]));
}
<span class='ident'>secret</span>.<span class='ident'>push</span>(<span class='ident'>lagrange_interpolate</span>(<span class='kw-2'>&amp;</span><span class='op'>*</span><span class='ident'>col_in</span>));
}
<span class='prelude-val'>Ok</span>(<span class='ident'>secret</span>)
}
</pre>
</section>
<section id='search' class="content hidden"></section>
<section class="footer"></section>
<aside id="help" class="hidden">
<div>
<h1 class="hidden">Help</h1>
<div class="shortcuts">
<h2>Keyboard Shortcuts</h2>
<dl>
<dt>?</dt>
<dd>Show this help dialog</dd>
<dt>S</dt>
<dd>Focus the search field</dd>
<dt>&larrb;</dt>
<dd>Move up in search results</dd>
<dt>&rarrb;</dt>
<dd>Move down in search results</dd>
<dt>&#9166;</dt>
<dd>Go to active search result</dd>
<dt>+</dt>
<dd>Collapse/expand all sections</dd>
</dl>
</div>
<div class="infos">
<h2>Search Tricks</h2>
<p>
Prefix searches with a type followed by a colon (e.g.
<code>fn:</code>) to restrict the search to a given type.
</p>
<p>
Accepted types are: <code>fn</code>, <code>mod</code>,
<code>struct</code>, <code>enum</code>,
<code>trait</code>, <code>type</code>, <code>macro</code>,
and <code>const</code>.
</p>
<p>
Search functions by type signature (e.g.
<code>vec -> usize</code> or <code>* -> vec</code>)
</p>
</div>
</div>
</aside>
<script>
window.rootPath = "../../../";
window.currentCrate = "rusty_secrets";
window.playgroundUrl = "";
</script>
<script src="../../../jquery.js"></script>
<script src="../../../main.js"></script>
<script defer src="../../../search-index.js"></script>
</body>
</html>

View File

@ -0,0 +1,248 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="rustdoc">
<meta name="description" content="Source to the Rust file `src/validation.rs`.">
<meta name="keywords" content="rust, rustlang, rust-lang">
<title>validation.rs.html -- source</title>
<link rel="stylesheet" type="text/css" href="../../../rustdoc.css">
<link rel="stylesheet" type="text/css" href="../../../main.css">
</head>
<body class="rustdoc">
<!--[if lte IE 8]>
<div class="warning">
This old browser is unsupported and will most likely display funky
things.
</div>
<![endif]-->
<nav class="sidebar">
</nav>
<nav class="sub">
<form class="search-form js-only">
<div class="search-container">
<input class="search-input" name="search"
autocomplete="off"
placeholder="Click or press S to search, ? for more options…"
type="search">
</div>
</form>
</nav>
<section id='main' class="content source"><pre class="line-numbers"><span id="1"> 1</span>
<span id="2"> 2</span>
<span id="3"> 3</span>
<span id="4"> 4</span>
<span id="5"> 5</span>
<span id="6"> 6</span>
<span id="7"> 7</span>
<span id="8"> 8</span>
<span id="9"> 9</span>
<span id="10">10</span>
<span id="11">11</span>
<span id="12">12</span>
<span id="13">13</span>
<span id="14">14</span>
<span id="15">15</span>
<span id="16">16</span>
<span id="17">17</span>
<span id="18">18</span>
<span id="19">19</span>
<span id="20">20</span>
<span id="21">21</span>
<span id="22">22</span>
<span id="23">23</span>
<span id="24">24</span>
<span id="25">25</span>
<span id="26">26</span>
<span id="27">27</span>
<span id="28">28</span>
<span id="29">29</span>
<span id="30">30</span>
<span id="31">31</span>
<span id="32">32</span>
<span id="33">33</span>
<span id="34">34</span>
<span id="35">35</span>
<span id="36">36</span>
<span id="37">37</span>
<span id="38">38</span>
<span id="39">39</span>
<span id="40">40</span>
<span id="41">41</span>
<span id="42">42</span>
<span id="43">43</span>
<span id="44">44</span>
<span id="45">45</span>
<span id="46">46</span>
<span id="47">47</span>
<span id="48">48</span>
<span id="49">49</span>
<span id="50">50</span>
<span id="51">51</span>
<span id="52">52</span>
<span id="53">53</span>
<span id="54">54</span>
<span id="55">55</span>
<span id="56">56</span>
<span id="57">57</span>
<span id="58">58</span>
<span id="59">59</span>
<span id="60">60</span>
<span id="61">61</span>
<span id="62">62</span>
<span id="63">63</span>
<span id="64">64</span>
<span id="65">65</span>
<span id="66">66</span>
<span id="67">67</span>
<span id="68">68</span>
<span id="69">69</span>
</pre><pre class='rust '>
<span class='kw'>use</span> <span class='ident'>custom_error</span>::<span class='ident'>other_io_err</span>;
<span class='kw'>use</span> <span class='ident'>merkle_sigs</span>::<span class='ident'>verify_data_vec_signature</span>;
<span class='kw'>use</span> <span class='ident'>share_format</span>;
<span class='kw'>use</span> <span class='ident'>share_format</span>::<span class='ident'>format_share_for_signing</span>;
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>error</span>::<span class='ident'>Error</span>;
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>io</span>;
<span class='kw'>pub</span> <span class='kw'>fn</span> <span class='ident'>process_and_validate_shares</span>(<span class='ident'>shares_strings</span>: <span class='ident'>Vec</span><span class='op'>&lt;</span><span class='ident'>String</span><span class='op'>&gt;</span>,
<span class='ident'>verify_signatures</span>: <span class='ident'>bool</span>)
<span class='op'>-&gt;</span> <span class='ident'>io</span>::<span class='prelude-ty'>Result</span><span class='op'>&lt;</span>(<span class='ident'>u8</span>, <span class='ident'>Vec</span><span class='op'>&lt;</span>(<span class='ident'>u8</span>, <span class='ident'>Vec</span><span class='op'>&lt;</span><span class='ident'>u8</span><span class='op'>&gt;</span>)<span class='op'>&gt;</span>)<span class='op'>&gt;</span> {
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>opt_k</span>: <span class='prelude-ty'>Option</span><span class='op'>&lt;</span><span class='ident'>u8</span><span class='op'>&gt;</span> <span class='op'>=</span> <span class='prelude-val'>None</span>;
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>opt_root_hash</span>: <span class='prelude-ty'>Option</span><span class='op'>&lt;</span><span class='ident'>Vec</span><span class='op'>&lt;</span><span class='ident'>u8</span><span class='op'>&gt;&gt;</span> <span class='op'>=</span> <span class='prelude-val'>None</span>;
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>shares</span>: <span class='ident'>Vec</span><span class='op'>&lt;</span>(<span class='ident'>u8</span>, <span class='ident'>Vec</span><span class='op'>&lt;</span><span class='ident'>u8</span><span class='op'>&gt;</span>)<span class='op'>&gt;</span> <span class='op'>=</span> <span class='ident'>Vec</span>::<span class='ident'>new</span>();
<span class='kw'>for</span> (<span class='ident'>counter</span>, <span class='ident'>line</span>) <span class='kw'>in</span> <span class='ident'>shares_strings</span>.<span class='ident'>iter</span>().<span class='ident'>enumerate</span>() {
<span class='kw'>let</span> (<span class='ident'>share_data</span>, <span class='ident'>k</span>, <span class='ident'>n</span>, <span class='ident'>sig_pair</span>) <span class='op'>=</span> <span class='macro'>try</span><span class='macro'>!</span>(<span class='ident'>share_format</span>::<span class='ident'>share_from_string</span>(<span class='ident'>line</span>,
<span class='ident'>verify_signatures</span>));
<span class='kw'>if</span> <span class='ident'>verify_signatures</span> {
<span class='kw'>if</span> <span class='ident'>sig_pair</span>.<span class='ident'>is_none</span>() {
<span class='kw'>return</span> <span class='prelude-val'>Err</span>(<span class='ident'>other_io_err</span>(<span class='string'>&quot;Signature is missing while shares are required to be \
signed.&quot;</span>,
<span class='prelude-val'>None</span>));
}
<span class='kw'>let</span> (<span class='ident'>signature</span>, <span class='ident'>p</span>) <span class='op'>=</span> <span class='ident'>sig_pair</span>.<span class='ident'>unwrap</span>();
<span class='kw'>let</span> <span class='ident'>root_hash</span> <span class='op'>=</span> <span class='ident'>p</span>.<span class='ident'>root_hash</span>.<span class='ident'>clone</span>();
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>rh</span>) <span class='op'>=</span> <span class='ident'>opt_root_hash</span>.<span class='ident'>clone</span>() {
<span class='kw'>if</span> <span class='ident'>root_hash</span> <span class='op'>!=</span> <span class='ident'>rh</span> {
<span class='kw'>return</span> <span class='prelude-val'>Err</span>(<span class='ident'>other_io_err</span>(<span class='string'>&quot;Root hash not matching&quot;</span>, <span class='prelude-val'>None</span>));
}
<span class='ident'>p</span>.<span class='ident'>validate</span>(<span class='kw-2'>&amp;</span><span class='ident'>rh</span>);
} <span class='kw'>else</span> {
<span class='ident'>opt_root_hash</span> <span class='op'>=</span> <span class='prelude-val'>Some</span>(<span class='ident'>root_hash</span>.<span class='ident'>clone</span>());
}
<span class='macro'>try</span><span class='macro'>!</span>(<span class='ident'>verify_data_vec_signature</span>(<span class='ident'>format_share_for_signing</span>(<span class='ident'>k</span>,
<span class='ident'>n</span>,
<span class='kw-2'>&amp;</span><span class='ident'>share_data</span>.<span class='ident'>as_slice</span>()),
<span class='kw-2'>&amp;</span>(<span class='ident'>signature</span>.<span class='ident'>to_vec</span>(), <span class='ident'>p</span>),
<span class='kw-2'>&amp;</span><span class='ident'>root_hash</span>)
.<span class='ident'>map_err</span>(<span class='op'>|</span><span class='ident'>e</span><span class='op'>|</span> <span class='ident'>other_io_err</span>(<span class='string'>&quot;Invalid signature&quot;</span>, <span class='prelude-val'>Some</span>(<span class='ident'>String</span>::<span class='ident'>from</span>(<span class='ident'>e</span>.<span class='ident'>description</span>())))));
}
<span class='kw'>if</span> <span class='kw'>let</span> <span class='prelude-val'>Some</span>(<span class='ident'>k_global</span>) <span class='op'>=</span> <span class='ident'>opt_k</span> {
<span class='kw'>if</span> <span class='ident'>k</span> <span class='op'>!=</span> <span class='ident'>k_global</span> {
<span class='kw'>return</span> <span class='prelude-val'>Err</span>(<span class='ident'>other_io_err</span>(<span class='string'>&quot;Incompatible shares&quot;</span>, <span class='prelude-val'>None</span>));
}
} <span class='kw'>else</span> {
<span class='ident'>opt_k</span> <span class='op'>=</span> <span class='prelude-val'>Some</span>(<span class='ident'>k</span>);
}
<span class='kw'>if</span> <span class='ident'>shares</span>.<span class='ident'>iter</span>().<span class='ident'>any</span>(<span class='op'>|</span><span class='ident'>s</span><span class='op'>|</span> <span class='ident'>s</span>.<span class='number'>0</span> <span class='op'>==</span> <span class='ident'>n</span>) {
<span class='kw'>return</span> <span class='prelude-val'>Err</span>(<span class='ident'>other_io_err</span>(<span class='string'>&quot;Duplicate Share Number&quot;</span>, <span class='prelude-val'>None</span>));
};
<span class='kw'>if</span> <span class='ident'>shares</span>.<span class='ident'>iter</span>().<span class='ident'>any</span>(<span class='op'>|</span><span class='ident'>s</span><span class='op'>|</span> <span class='ident'>s</span>.<span class='number'>1</span> <span class='op'>==</span> <span class='ident'>share_data</span>) {
<span class='kw'>return</span> <span class='prelude-val'>Err</span>(<span class='ident'>other_io_err</span>(<span class='string'>&quot;Duplicate Share Data&quot;</span>, <span class='prelude-val'>None</span>));
};
<span class='ident'>shares</span>.<span class='ident'>push</span>((<span class='ident'>n</span>, <span class='ident'>share_data</span>));
<span class='kw'>if</span> <span class='ident'>counter</span> <span class='op'>+</span> <span class='number'>1</span> <span class='op'>==</span> <span class='ident'>k</span> <span class='kw'>as</span> <span class='ident'>usize</span> {
<span class='kw'>return</span> <span class='prelude-val'>Ok</span>((<span class='ident'>k</span>, <span class='ident'>shares</span>));
}
}
<span class='prelude-val'>Err</span>(<span class='ident'>other_io_err</span>(<span class='string'>&quot;Not enough shares provided!&quot;</span>, <span class='prelude-val'>None</span>))
}
</pre>
</section>
<section id='search' class="content hidden"></section>
<section class="footer"></section>
<aside id="help" class="hidden">
<div>
<h1 class="hidden">Help</h1>
<div class="shortcuts">
<h2>Keyboard Shortcuts</h2>
<dl>
<dt>?</dt>
<dd>Show this help dialog</dd>
<dt>S</dt>
<dd>Focus the search field</dd>
<dt>&larrb;</dt>
<dd>Move up in search results</dd>
<dt>&rarrb;</dt>
<dd>Move down in search results</dd>
<dt>&#9166;</dt>
<dd>Go to active search result</dd>
<dt>+</dt>
<dd>Collapse/expand all sections</dd>
</dl>
</div>
<div class="infos">
<h2>Search Tricks</h2>
<p>
Prefix searches with a type followed by a colon (e.g.
<code>fn:</code>) to restrict the search to a given type.
</p>
<p>
Accepted types are: <code>fn</code>, <code>mod</code>,
<code>struct</code>, <code>enum</code>,
<code>trait</code>, <code>type</code>, <code>macro</code>,
and <code>const</code>.
</p>
<p>
Search functions by type signature (e.g.
<code>vec -> usize</code> or <code>* -> vec</code>)
</p>
</div>
</div>
</aside>
<script>
window.rootPath = "../../../";
window.currentCrate = "rusty_secrets";
window.playgroundUrl = "";
</script>
<script src="../../../jquery.js"></script>
<script src="../../../main.js"></script>
<script defer src="../../../search-index.js"></script>
</body>
</html>

View File

@ -1,8 +1,7 @@
syntax = "proto3";
message ShareData {
bytes shamirData = 1;
bytes signature = 2;
bytes shamir_data = 1;
repeated bytes signature = 2;
bytes proof = 3;
}

View File

@ -1,6 +1,4 @@
pub use std::convert;
pub use std::io::prelude::*;
use std::convert;
use std::error;
use std::fmt;
use std::io;
@ -14,8 +12,12 @@ pub struct Error {
}
impl Error {
/// Initializes a new error with a description and optional detail string.
pub fn new(descr: &'static str, detail: Option<String>) -> Error {
Error { descr: descr, detail: detail }
Error {
descr: descr,
detail: detail,
}
}
}
@ -23,17 +25,21 @@ impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.detail {
None => write!(f, "{}", self.descr),
Some(ref detail) => write!(f, "{} ({})", self.descr, detail)
Some(ref detail) => write!(f, "{} ({})", self.descr, detail),
}
}
}
impl error::Error for Error {
fn description(&self) -> &str { self.descr }
fn cause(&self) -> Option<&error::Error> { None }
fn description(&self) -> &str {
self.descr
}
fn cause(&self) -> Option<&error::Error> {
None
}
}
impl convert::From<Error> for io::Error {
impl From<Error> for io::Error {
fn from(me: Error) -> io::Error {
io::Error::new(io::ErrorKind::Other, me)
}
@ -42,23 +48,24 @@ impl convert::From<Error> for io::Error {
/// Returns an `io::Error` from description string and optional detail string.
/// Particularly useful in `Result` expressions.
pub fn other_io_err(descr: &'static str, detail: Option<String>) -> io::Error {
convert::From::from(
Error::new(descr, detail)
)
convert::From::from(Error::new(descr, detail))
}
/// maps a `ParseIntError` to an `io::Error`
pub fn pie2io(p: num::ParseIntError) -> io::Error {
convert::From::from(
Error::new("Integer parsing error", Some(p.to_string()))
)
convert::From::from(Error::new("Integer parsing error", Some(p.to_string())))
}
#[test]
fn test_custom_error() {
#[cfg(test)]
mod tests_custom_err {
use std::error;
use custom_error;
#[test]
fn test_custom_error() {
let desc = "Boring error description";
let detail = "More of it";
let ewd = Error::new(desc, Some(detail.to_string()));
let ewd = custom_error::Error::new(desc, Some(detail.to_string()));
assert_eq!(error::Error::description(&ewd), desc);
match error::Error::cause(&ewd) {
@ -66,6 +73,22 @@ fn test_custom_error() {
None => assert!(true),
}
let _formated_err = format!("{}", ewd);
let ewod = Error::new(desc, None);
let ewod = custom_error::Error::new(desc, None);
let _formated_err = format!("{}", ewod);
}
}
#[cfg(test)]
mod tests_std_err {
use std::error::Error;
use custom_error::pie2io;
#[test]
fn test_parse_errors() {
let nan = "2a".to_string();
match nan.parse::<u8>().map_err(pie2io) {
Ok(_) => assert!(false),
Err(x) => assert_eq!("Integer parsing error", x.description()),
}
}
}

View File

@ -1,7 +1,7 @@
//! This module provides the Gf256 type which is used to represent
//! elements of a finite field with 256 elements.
use std::ops::{ Add, Sub, Mul, Div };
use std::ops::{Add, Div, Mul, Sub};
include!(concat!(env!("OUT_DIR"), "/nothinghardcoded.rs"));
@ -12,7 +12,7 @@ fn get_tables() -> &'static Tables {
/// Type for elements of a finite field with 256 elements
#[derive(Copy,Clone,PartialEq,Eq)]
pub struct Gf256 {
pub poly: u8
pub poly: u8,
}
impl Gf256 {

40
src/interpolation.rs Normal file
View File

@ -0,0 +1,40 @@
use gf256::Gf256;
use std::io;
use std::io::prelude::*;
/// evaluates a polynomial at x=1, 2, 3, ... n (inclusive)
pub fn encode<W: Write>(src: &[u8], n: u8, w: &mut W) -> io::Result<()> {
for raw_x in 1..((n as u16) + 1) {
let x = Gf256::from_byte(raw_x as u8);
let mut fac = Gf256::one();
let mut acc = Gf256::zero();
for &coeff in src.iter() {
acc = acc + fac * Gf256::from_byte(coeff);
fac = fac * x;
}
try!(w.write(&[acc.to_byte()]));
}
Ok(())
}
/// evaluates an interpolated polynomial at `Gf256::zero()` where
/// the polynomial is determined using Lagrangian interpolation
/// based on the given x/y coordinates `src`.
pub fn lagrange_interpolate(src: &[(u8, u8)]) -> u8 {
let mut sum = Gf256::zero();
for (i, &(raw_xi, raw_yi)) in src.iter().enumerate() {
let xi = Gf256::from_byte(raw_xi);
let yi = Gf256::from_byte(raw_yi);
let mut prod = Gf256::one();
for (j, &(raw_xj, _)) in src.iter().enumerate() {
if i != j {
let xj = Gf256::from_byte(raw_xj);
let delta = xi - xj;
assert!(delta.poly != 0, "Duplicate shares");
prod = prod * xj / delta;
}
}
sum = sum + prod * yi;
}
sum.to_byte()
}

View File

@ -1,215 +1,33 @@
#![deny(
missing_docs,
missing_debug_implementations, missing_copy_implementations,
trivial_casts, trivial_numeric_casts,
unsafe_code, unstable_features,
unused_import_braces, unused_qualifications
)]
//! `RustySecrets` implements Shamir Secret Sharing in Rust. It provides the possibility to sign shares.
extern crate protobuf;
extern crate rustc_serialize as serialize;
extern crate rand;
extern crate merkle_sigs;
extern crate ring;
use rand::{ Rng, OsRng };
use serialize::base64::{ self, FromBase64, ToBase64 };
use ring::digest::{Algorithm, SHA512};
#[allow(non_upper_case_globals)]
static digest: &'static Algorithm = &SHA512;
mod custom_error;
mod gf256;
use gf256::Gf256;
mod interpolation;
mod share_data;
mod share_format;
mod sss;
mod validation;
use std::io;
use std::iter::repeat;
pub use sss::generate_shares;
pub use sss::recover_secret;
/// Generate generic errors that typeset with `io::Error`.
pub mod custom_error;
use custom_error::*;
use protobuf::Message;
mod ShareDataMod;
pub use ShareDataMod::{ShareData};
/// Performs threshold k-out-of-n Shamir secret sharing.
///
/// # Examples
///
/// ```
/// use rusty_secrets::{generate_shares};
/// let secret = "These programs were never about terrorism: theyre about economic spying, social control, and diplomatic manipulation. Theyre about power.".to_string();
///
/// match generate_shares(7, 10, &secret.into_bytes()){
/// Ok(shares) => {
/// // Do something with the shares
/// },
/// Err(_) => {}// Deal with error}
/// }
/// ```
pub fn generate_shares(k: u8, n: u8, secret: &[u8]) -> io::Result<Vec<String>> {
if k > n {
return Err(other_io_err("Threshold K can not be larger than N", None));
}
let shares = try!(secret_share(&*secret, k, n));
let config = base64::Config {
pad: false,
..base64::STANDARD
};
let mut result = Vec::with_capacity(n as usize);
for (index, share) in shares.into_iter().enumerate() {
let mut share_protobuf = ShareData::new();
share_protobuf.set_shamirData(share);
let b64_share = share_protobuf.write_to_bytes().unwrap().to_base64(config);
let string = format!("{}-{}-{}", k, index+1, b64_share);
result.push(string);
}
Ok(result)
}
fn process_shares(shares_strings: Vec<String>) -> io::Result<(u8, Vec<(u8, Vec<u8>)>)> {
let mut opt_k_l: Option<(u8, usize)> = None;
let mut counter = 0u8;
let mut shares: Vec<(u8,Vec<u8>)> = Vec::new();
for line in shares_strings {
let parts: Vec<_> = line.trim().split('-').collect();
if parts.len() != 3 {
return Err(other_io_err("Share parse error: Expected 3 parts separated by a minus sign", None));
}
let (k, n, p3) = {
let mut iter = parts.into_iter();
let k = try!(iter.next().unwrap().parse::<u8>().map_err(pie2io));
let n = try!(iter.next().unwrap().parse::<u8>().map_err(pie2io));
let p3 = iter.next().unwrap();
(k, n, p3)
};
if k < 1 || n < 1 {
return Err(other_io_err("Share parse error: Illegal K,N parameters", None));
}
let raw_data = try!(
p3.from_base64().map_err(|_| other_io_err(
"Share parse error: Base64 decoding of data block failed", None ))
);
let protobuf_data = try!(protobuf::parse_from_bytes::<ShareData>(raw_data.as_slice())
.map_err(|_| other_io_err("Share parse error: Protobuffer could not be decoded.", None )));
let data = Vec::from(protobuf_data.get_shamirData());
if let Some((ck, cl)) = opt_k_l {
if ck != k || cl != data.len() {
return Err(other_io_err("Incompatible shares", None));
}
} else {
opt_k_l = Some((k, data.len()));
}
if shares.iter().any(|s| s.0 == n) {
return Err(other_io_err("Duplicate Share Number", None));
};
if shares.iter().any(|s| s.1 == data) {
return Err(other_io_err("Duplicate Share Data", None));
};
shares.push((n, data));
counter += 1;
if counter == k {
return Ok((k, shares));
}
}
Err(other_io_err("Not enough shares provided!", None))
}
/// Recovers the secret from a k-out-of-n Shamir secret sharing.
///
/// At least `k` distinct shares need to be provided to recover the share.
///
/// # Examples
///
/// ```
/// use rusty_secrets::{recover_secret};
/// let share1 = "2-1-Cha7s14Q/mSwWko0ittr+/Uf79RHQMIP".to_string();
/// let share2 = "2-4-ChaydsUJDypD9ZWxwvIICh/cmZvzusOF".to_string();
/// let shares = vec![share1, share2];
///
/// match recover_secret(shares) {
/// Ok(secret) => {
/// // Do something with the secret
/// },
/// Err(e) => {
/// // Deal with the error
/// }
/// }
/// ```
pub fn recover_secret(shares: Vec<String>) -> io::Result<Vec<u8>> {
let (k, shares) = try!(process_shares(shares));
let slen = shares[0].1.len();
let mut col_in = Vec::with_capacity(k as usize);
let mut secret = Vec::with_capacity(slen);
for byteindex in 0 .. slen {
col_in.clear();
for s in shares.iter().take(k as usize) {
col_in.push((s.0, s.1[byteindex]));
}
secret.push(lagrange_interpolate(&*col_in));
}
Ok(secret) as io::Result<Vec<u8>>
}
fn new_vec<T: Clone>(n: usize, x: T) -> Vec<T> {
repeat(x).take(n).collect()
}
/// evaluates a polynomial at x=1, 2, 3, ... n (inclusive)
fn encode<W: Write>(src: &[u8], n: u8, w: &mut W) -> io::Result<()> {
for raw_x in 1 .. ((n as u16) + 1) {
let x = Gf256::from_byte(raw_x as u8);
let mut fac = Gf256::one();
let mut acc = Gf256::zero();
for &coeff in src.iter() {
acc = acc + fac * Gf256::from_byte(coeff);
fac = fac * x;
}
try!(w.write(&[acc.to_byte()]));
}
Ok(())
}
/// evaluates an interpolated polynomial at `Gf256::zero()` where
/// the polynomial is determined using Lagrangian interpolation
/// based on the given x/y coordinates `src`.
fn lagrange_interpolate(src: &[(u8, u8)]) -> u8 {
let mut sum = Gf256::zero();
for (i, &(raw_xi, raw_yi)) in src.iter().enumerate() {
let xi = Gf256::from_byte(raw_xi);
let yi = Gf256::from_byte(raw_yi);
let mut prod = Gf256::one();
for (j, &(raw_xj, _)) in src.iter().enumerate() {
if i != j {
let xj = Gf256::from_byte(raw_xj);
let delta = xi - xj;
assert!(delta.poly !=0, "Duplicate shares");
prod = prod * xj / delta;
}
}
sum = sum + prod * yi;
}
sum.to_byte()
}
fn secret_share(src: &[u8], k: u8, n: u8) -> io::Result<Vec<Vec<u8>>> {
let mut result = Vec::with_capacity(n as usize);
for _ in 0 .. (n as usize) {
result.push(new_vec(src.len(), 0u8));
}
let mut col_in = new_vec(k as usize, 0u8);
let mut col_out = Vec::with_capacity(n as usize);
let mut osrng = try!(OsRng::new());
for (c, &s) in src.iter().enumerate() {
col_in[0] = s;
osrng.fill_bytes(&mut col_in[1..]);
col_out.clear();
try!(encode(&*col_in, n, &mut col_out));
for (&y, share) in col_out.iter().zip(result.iter_mut()) {
share[c] = y;
}
}
Ok(result)
}
#[cfg(test)]
mod tests;

View File

@ -23,8 +23,8 @@ use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions;
#[derive(Clone,Default)]
pub struct ShareData {
// message fields
shamirData: ::protobuf::SingularField<::std::vec::Vec<u8>>,
signature: ::protobuf::SingularField<::std::vec::Vec<u8>>,
shamir_data: ::protobuf::SingularField<::std::vec::Vec<u8>>,
signature: ::protobuf::RepeatedField<::std::vec::Vec<u8>>,
proof: ::protobuf::SingularField<::std::vec::Vec<u8>>,
// special fields
unknown_fields: ::protobuf::UnknownFields,
@ -47,8 +47,8 @@ impl ShareData {
unsafe {
instance.get(|| {
ShareData {
shamirData: ::protobuf::SingularField::none(),
signature: ::protobuf::SingularField::none(),
shamir_data: ::protobuf::SingularField::none(),
signature: ::protobuf::RepeatedField::new(),
proof: ::protobuf::SingularField::none(),
unknown_fields: ::protobuf::UnknownFields::new(),
cached_size: ::std::cell::Cell::new(0),
@ -57,76 +57,65 @@ impl ShareData {
}
}
// optional bytes shamirData = 1;
// optional bytes shamir_data = 1;
pub fn clear_shamirData(&mut self) {
self.shamirData.clear();
pub fn clear_shamir_data(&mut self) {
self.shamir_data.clear();
}
pub fn has_shamirData(&self) -> bool {
self.shamirData.is_some()
pub fn has_shamir_data(&self) -> bool {
self.shamir_data.is_some()
}
// Param is passed by value, moved
pub fn set_shamirData(&mut self, v: ::std::vec::Vec<u8>) {
self.shamirData = ::protobuf::SingularField::some(v);
pub fn set_shamir_data(&mut self, v: ::std::vec::Vec<u8>) {
self.shamir_data = ::protobuf::SingularField::some(v);
}
// Mutable pointer to the field.
// If field is not initialized, it is initialized with default value first.
pub fn mut_shamirData(&mut self) -> &mut ::std::vec::Vec<u8> {
if self.shamirData.is_none() {
self.shamirData.set_default();
pub fn mut_shamir_data(&mut self) -> &mut ::std::vec::Vec<u8> {
if self.shamir_data.is_none() {
self.shamir_data.set_default();
};
self.shamirData.as_mut().unwrap()
self.shamir_data.as_mut().unwrap()
}
// Take field
pub fn take_shamirData(&mut self) -> ::std::vec::Vec<u8> {
self.shamirData.take().unwrap_or_else(|| ::std::vec::Vec::new())
pub fn take_shamir_data(&mut self) -> ::std::vec::Vec<u8> {
self.shamir_data.take().unwrap_or_else(|| ::std::vec::Vec::new())
}
pub fn get_shamirData(&self) -> &[u8] {
match self.shamirData.as_ref() {
pub fn get_shamir_data(&self) -> &[u8] {
match self.shamir_data.as_ref() {
Some(v) => &v,
None => &[],
}
}
// optional bytes signature = 2;
// repeated bytes signature = 2;
pub fn clear_signature(&mut self) {
self.signature.clear();
}
pub fn has_signature(&self) -> bool {
self.signature.is_some()
}
// Param is passed by value, moved
pub fn set_signature(&mut self, v: ::std::vec::Vec<u8>) {
self.signature = ::protobuf::SingularField::some(v);
pub fn set_signature(&mut self, v: ::protobuf::RepeatedField<::std::vec::Vec<u8>>) {
self.signature = v;
}
// Mutable pointer to the field.
// If field is not initialized, it is initialized with default value first.
pub fn mut_signature(&mut self) -> &mut ::std::vec::Vec<u8> {
if self.signature.is_none() {
self.signature.set_default();
};
self.signature.as_mut().unwrap()
pub fn mut_signature(&mut self) -> &mut ::protobuf::RepeatedField<::std::vec::Vec<u8>> {
&mut self.signature
}
// Take field
pub fn take_signature(&mut self) -> ::std::vec::Vec<u8> {
self.signature.take().unwrap_or_else(|| ::std::vec::Vec::new())
pub fn take_signature(&mut self) -> ::protobuf::RepeatedField<::std::vec::Vec<u8>> {
::std::mem::replace(&mut self.signature, ::protobuf::RepeatedField::new())
}
pub fn get_signature(&self) -> &[u8] {
match self.signature.as_ref() {
Some(v) => &v,
None => &[],
}
pub fn get_signature(&self) -> &[::std::vec::Vec<u8>] {
&self.signature
}
// optional bytes proof = 3;
@ -176,10 +165,10 @@ impl ::protobuf::Message for ShareData {
let (field_number, wire_type) = try!(is.read_tag_unpack());
match field_number {
1 => {
try!(::protobuf::rt::read_singular_bytes_into(wire_type, is, &mut self.shamirData));
try!(::protobuf::rt::read_singular_bytes_into(wire_type, is, &mut self.shamir_data));
},
2 => {
try!(::protobuf::rt::read_singular_bytes_into(wire_type, is, &mut self.signature));
try!(::protobuf::rt::read_repeated_bytes_into(wire_type, is, &mut self.signature));
},
3 => {
try!(::protobuf::rt::read_singular_bytes_into(wire_type, is, &mut self.proof));
@ -196,7 +185,7 @@ impl ::protobuf::Message for ShareData {
#[allow(unused_variables)]
fn compute_size(&self) -> u32 {
let mut my_size = 0;
for value in &self.shamirData {
for value in &self.shamir_data {
my_size += ::protobuf::rt::bytes_size(1, &value);
};
for value in &self.signature {
@ -211,10 +200,10 @@ impl ::protobuf::Message for ShareData {
}
fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> {
if let Some(v) = self.shamirData.as_ref() {
if let Some(v) = self.shamir_data.as_ref() {
try!(os.write_bytes(1, &v));
};
if let Some(v) = self.signature.as_ref() {
for v in &self.signature {
try!(os.write_bytes(2, &v));
};
if let Some(v) = self.proof.as_ref() {
@ -263,13 +252,12 @@ impl ::protobuf::MessageStatic for ShareData {
descriptor.get(|| {
let mut fields = ::std::vec::Vec::new();
fields.push(::protobuf::reflect::accessor::make_singular_bytes_accessor(
"shamirData",
ShareData::has_shamirData,
ShareData::get_shamirData,
"shamir_data",
ShareData::has_shamir_data,
ShareData::get_shamir_data,
));
fields.push(::protobuf::reflect::accessor::make_singular_bytes_accessor(
fields.push(::protobuf::reflect::accessor::make_repeated_bytes_accessor(
"signature",
ShareData::has_signature,
ShareData::get_signature,
));
fields.push(::protobuf::reflect::accessor::make_singular_bytes_accessor(
@ -289,7 +277,7 @@ impl ::protobuf::MessageStatic for ShareData {
impl ::protobuf::Clear for ShareData {
fn clear(&mut self) {
self.clear_shamirData();
self.clear_shamir_data();
self.clear_signature();
self.clear_proof();
self.unknown_fields.clear();
@ -298,7 +286,7 @@ impl ::protobuf::Clear for ShareData {
impl ::std::cmp::PartialEq for ShareData {
fn eq(&self, other: &ShareData) -> bool {
self.shamirData == other.shamirData &&
self.shamir_data == other.shamir_data &&
self.signature == other.signature &&
self.proof == other.proof &&
self.unknown_fields == other.unknown_fields
@ -312,30 +300,31 @@ impl ::std::fmt::Debug for ShareData {
}
static file_descriptor_proto_data: &'static [u8] = &[
0x0a, 0x0f, 0x53, 0x68, 0x61, 0x72, 0x65, 0x44, 0x61, 0x74, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x22, 0x5f, 0x0a, 0x09, 0x53, 0x68, 0x61, 0x72, 0x65, 0x44, 0x61, 0x74, 0x61, 0x12, 0x1e,
0x0a, 0x0a, 0x73, 0x68, 0x61, 0x6d, 0x69, 0x72, 0x44, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01,
0x28, 0x0c, 0x52, 0x0a, 0x73, 0x68, 0x61, 0x6d, 0x69, 0x72, 0x44, 0x61, 0x74, 0x61, 0x12, 0x1c,
0x0a, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28,
0x0c, 0x52, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x12, 0x14, 0x0a, 0x05,
0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x70, 0x72, 0x6f,
0x6f, 0x66, 0x4a, 0xfc, 0x01, 0x0a, 0x06, 0x12, 0x04, 0x00, 0x00, 0x06, 0x01, 0x0a, 0x08, 0x0a,
0x01, 0x0c, 0x12, 0x03, 0x00, 0x00, 0x12, 0x0a, 0x0a, 0x0a, 0x02, 0x04, 0x00, 0x12, 0x04, 0x02,
0x00, 0x06, 0x01, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x00, 0x01, 0x12, 0x03, 0x02, 0x08, 0x11, 0x0a,
0x0b, 0x0a, 0x04, 0x04, 0x00, 0x02, 0x00, 0x12, 0x03, 0x03, 0x08, 0x1d, 0x0a, 0x0d, 0x0a, 0x05,
0x04, 0x00, 0x02, 0x00, 0x04, 0x12, 0x04, 0x03, 0x08, 0x02, 0x13, 0x0a, 0x0c, 0x0a, 0x05, 0x04,
0x00, 0x02, 0x00, 0x05, 0x12, 0x03, 0x03, 0x08, 0x0d, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02,
0x00, 0x01, 0x12, 0x03, 0x03, 0x0e, 0x18, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, 0x03,
0x12, 0x03, 0x03, 0x1b, 0x1c, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x00, 0x02, 0x01, 0x12, 0x03, 0x04,
0x08, 0x1d, 0x0a, 0x0d, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x01, 0x04, 0x12, 0x04, 0x04, 0x08, 0x03,
0x1d, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x01, 0x05, 0x12, 0x03, 0x04, 0x08, 0x0d, 0x0a,
0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x01, 0x01, 0x12, 0x03, 0x04, 0x0e, 0x17, 0x0a, 0x0c, 0x0a,
0x05, 0x04, 0x00, 0x02, 0x01, 0x03, 0x12, 0x03, 0x04, 0x1b, 0x1c, 0x0a, 0x0b, 0x0a, 0x04, 0x04,
0x00, 0x02, 0x02, 0x12, 0x03, 0x05, 0x08, 0x1d, 0x0a, 0x0d, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x02,
0x04, 0x12, 0x04, 0x05, 0x08, 0x04, 0x1d, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x02, 0x05,
0x12, 0x03, 0x05, 0x08, 0x0d, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x02, 0x01, 0x12, 0x03,
0x05, 0x0e, 0x13, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x02, 0x03, 0x12, 0x03, 0x05, 0x1b,
0x1c, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x0a, 0x18, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x53, 0x68, 0x61, 0x72, 0x65,
0x44, 0x61, 0x74, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x60, 0x0a, 0x09, 0x53, 0x68,
0x61, 0x72, 0x65, 0x44, 0x61, 0x74, 0x61, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x68, 0x61, 0x6d, 0x69,
0x72, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x73, 0x68,
0x61, 0x6d, 0x69, 0x72, 0x44, 0x61, 0x74, 0x61, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x69, 0x67, 0x6e,
0x61, 0x74, 0x75, 0x72, 0x65, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x09, 0x73, 0x69, 0x67,
0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x18,
0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x70, 0x72, 0x6f, 0x6f, 0x66, 0x4a, 0xfb, 0x01, 0x0a,
0x06, 0x12, 0x04, 0x00, 0x00, 0x06, 0x01, 0x0a, 0x08, 0x0a, 0x01, 0x0c, 0x12, 0x03, 0x00, 0x00,
0x12, 0x0a, 0x0a, 0x0a, 0x02, 0x04, 0x00, 0x12, 0x04, 0x02, 0x00, 0x06, 0x01, 0x0a, 0x0a, 0x0a,
0x03, 0x04, 0x00, 0x01, 0x12, 0x03, 0x02, 0x08, 0x11, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x00, 0x02,
0x00, 0x12, 0x03, 0x03, 0x08, 0x1e, 0x0a, 0x0d, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, 0x04, 0x12,
0x04, 0x03, 0x08, 0x02, 0x13, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, 0x05, 0x12, 0x03,
0x03, 0x08, 0x0d, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, 0x01, 0x12, 0x03, 0x03, 0x0e,
0x19, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x00, 0x03, 0x12, 0x03, 0x03, 0x1c, 0x1d, 0x0a,
0x0b, 0x0a, 0x04, 0x04, 0x00, 0x02, 0x01, 0x12, 0x03, 0x04, 0x08, 0x25, 0x0a, 0x0c, 0x0a, 0x05,
0x04, 0x00, 0x02, 0x01, 0x04, 0x12, 0x03, 0x04, 0x08, 0x10, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00,
0x02, 0x01, 0x05, 0x12, 0x03, 0x04, 0x11, 0x16, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x01,
0x01, 0x12, 0x03, 0x04, 0x17, 0x20, 0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x01, 0x03, 0x12,
0x03, 0x04, 0x23, 0x24, 0x0a, 0x0b, 0x0a, 0x04, 0x04, 0x00, 0x02, 0x02, 0x12, 0x03, 0x05, 0x08,
0x18, 0x0a, 0x0d, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x02, 0x04, 0x12, 0x04, 0x05, 0x08, 0x04, 0x25,
0x0a, 0x0c, 0x0a, 0x05, 0x04, 0x00, 0x02, 0x02, 0x05, 0x12, 0x03, 0x05, 0x08, 0x0d, 0x0a, 0x0c,
0x0a, 0x05, 0x04, 0x00, 0x02, 0x02, 0x01, 0x12, 0x03, 0x05, 0x0e, 0x13, 0x0a, 0x0c, 0x0a, 0x05,
0x04, 0x00, 0x02, 0x02, 0x03, 0x12, 0x03, 0x05, 0x16, 0x17, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x33,
];
static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy {

86
src/share_format.rs Normal file
View File

@ -0,0 +1,86 @@
use custom_error::{other_io_err, pie2io};
use digest;
use merkle_sigs::Proof;
use merkle_sigs::PublicKey;
use protobuf;
use protobuf::{Message, RepeatedField};
use serialize;
use serialize::base64::{self, FromBase64, ToBase64};
use share_data::ShareData;
use std::io;
fn base64_config() -> serialize::base64::Config {
base64::Config { pad: false, ..base64::STANDARD }
}
pub fn share_string_from(share: Vec<u8>,
threshold: u8,
share_num: u8,
signature_pair: Option<(Vec<Vec<u8>>, Proof<PublicKey>)>)
-> String {
let mut share_protobuf = ShareData::new();
share_protobuf.set_shamir_data(share);
if signature_pair.is_some() {
let (signature, proof) = signature_pair.unwrap();
share_protobuf.set_signature(RepeatedField::from_vec(signature));
share_protobuf.set_proof(proof.write_to_bytes().unwrap());
}
let b64_share = share_protobuf.write_to_bytes().unwrap().to_base64(base64_config());
format!("{}-{}-{}", threshold, share_num, b64_share)
}
pub fn share_from_string
(s: &str,
is_signed: bool)
-> io::Result<(Vec<u8>, u8, u8, Option<(Vec<Vec<u8>>, Proof<PublicKey>)>)> {
let parts: Vec<_> = s.trim().split('-').collect();
if parts.len() != 3 {
return Err(other_io_err("Share parse error: Expected 3 parts separated by a minus sign",
None));
}
let (k, n, p3) = {
let mut iter = parts.into_iter();
let k = try!(iter.next().unwrap().parse::<u8>().map_err(pie2io));
let n = try!(iter.next().unwrap().parse::<u8>().map_err(pie2io));
let p3 = iter.next().unwrap();
(k, n, p3)
};
if k < 1 || n < 1 {
return Err(other_io_err("Share parse error: Illegal K,N parameters", None));
}
let raw_data = try!(p3.from_base64().map_err(|_| {
other_io_err("Share parse error: Base64 decoding of data block failed",
None)
}));
let protobuf_data = try!(protobuf::parse_from_bytes::<ShareData>(raw_data.as_slice())
.map_err(|_| other_io_err("Share parse error: Protobuffer could not be decoded.", None)));
let share = Vec::from(protobuf_data.get_shamir_data());
if is_signed {
let p = Proof::parse_from_bytes(protobuf_data.get_proof(), digest).unwrap().unwrap();
let proof = Proof {
algorithm: digest,
lemma: p.lemma,
root_hash: p.root_hash,
value: PublicKey::from_vec(p.value, digest).unwrap(),
};
let signature = protobuf_data.get_signature();
Ok((share, k, n, Some((Vec::from(signature), proof))))
} else {
Ok((share, k, n, None))
}
}
pub fn format_share_for_signing(k: u8, i: u8, data: &[u8]) -> Vec<u8> {
format!("{}-{}-{}", k, i, data.to_base64(base64_config())).into_bytes()
}

126
src/sss.rs Normal file
View File

@ -0,0 +1,126 @@
use custom_error::other_io_err;
use digest;
use interpolation::{encode, lagrange_interpolate};
use merkle_sigs::sign_data_vec;
use rand::{OsRng, Rng};
use share_format::format_share_for_signing;
use share_format::share_string_from;
use std::io;
use std::iter::repeat;
use validation::process_and_validate_shares;
fn new_vec<T: Clone>(n: usize, x: T) -> Vec<T> {
repeat(x).take(n).collect()
}
/// Performs threshold k-out-of-n Shamir secret sharing.
///
/// # Examples
///
/// ```
/// use rusty_secrets::generate_shares;
/// let secret = "These programs were never about terrorism: theyre about economic spying,
/// social control, and diplomatic manipulation. Theyre about power.".to_string();
///
/// match generate_shares(7, 10, &secret.into_bytes(), true){
/// Ok(shares) => {
/// // Do something with the shares
/// },
/// Err(_) => {}// Deal with error}
/// }
/// ```
pub fn generate_shares(k: u8, n: u8, secret: &[u8], sign_shares: bool) -> io::Result<Vec<String>> {
if k > n {
return Err(other_io_err("Threshold K can not be larger than N", None));
}
let shares = try!(secret_share(&*secret, k, n));
let signatures = if sign_shares {
let shares_to_sign = shares.iter()
.enumerate()
.map(|(i, x)| format_share_for_signing(k, (i + 1) as u8, x))
.collect::<Vec<_>>();
let sign = sign_data_vec(&shares_to_sign, digest)
.unwrap()
.into_iter()
.map(Some)
.collect::<Vec<_>>();
Some(sign)
} else {
None
};
let mut result = Vec::with_capacity(n as usize);
for ((index, share), signature_pair) in
shares.into_iter()
.enumerate()
.zip(signatures.unwrap_or_else(|| vec![None; n as usize]).into_iter()) {
let share_string = share_string_from(share, k, (index + 1) as u8, signature_pair);
result.push(share_string);
}
Ok(result)
}
pub fn secret_share(src: &[u8], k: u8, n: u8) -> io::Result<Vec<Vec<u8>>> {
let mut result = Vec::with_capacity(n as usize);
for _ in 0..(n as usize) {
result.push(new_vec(src.len(), 0u8));
}
let mut col_in = new_vec(k as usize, 0u8);
let mut col_out = Vec::with_capacity(n as usize);
let mut osrng = try!(OsRng::new());
for (c, &s) in src.iter().enumerate() {
col_in[0] = s;
osrng.fill_bytes(&mut col_in[1..]);
col_out.clear();
try!(encode(&*col_in, n, &mut col_out));
for (&y, share) in col_out.iter().zip(result.iter_mut()) {
share[c] = y;
}
}
Ok(result)
}
/// Recovers the secret from a k-out-of-n Shamir secret sharing.
///
/// At least `k` distinct shares need to be provided to recover the share.
///
/// # Examples
///
/// ```
/// use rusty_secrets::recover_secret;
/// let share1 = "2-1-Cha7s14Q/mSwWko0ittr+/Uf79RHQMIP".to_string();
/// let share2 = "2-4-ChaydsUJDypD9ZWxwvIICh/cmZvzusOF".to_string();
/// let shares = vec![share1, share2];
///
/// match recover_secret(shares, false) {
/// Ok(secret) => {
/// // Do something with the secret
/// },
/// Err(e) => {
/// // Deal with the error
/// }
/// }
/// ```
pub fn recover_secret(shares: Vec<String>, verify_signatures: bool) -> io::Result<Vec<u8>> {
let (k, shares) = try!(process_and_validate_shares(shares, verify_signatures));
let slen = shares[0].1.len();
let mut col_in = Vec::with_capacity(k as usize);
let mut secret = Vec::with_capacity(slen);
for byteindex in 0..slen {
col_in.clear();
for s in shares.iter().take(k as usize) {
col_in.push((s.0, s.1[byteindex]));
}
secret.push(lagrange_interpolate(&*col_in));
}
Ok(secret)
}

1
src/tests/mod.rs Normal file
View File

@ -0,0 +1 @@
mod test_vectors;

79
src/tests/test_vectors.rs Normal file
View File

@ -0,0 +1,79 @@
extern crate protobuf;
extern crate rustc_serialize as serialize;
use protobuf::Message;
use share_data;
use sss::recover_secret;
use serialize::base64::{self, FromBase64, ToBase64};
pub fn wrap_from_sellibitze(share: &str) -> String {
let parts: Vec<_> = share.trim().split('-').collect();
let share_data = parts[2].from_base64().unwrap();
let config = base64::Config { pad: false, ..base64::STANDARD };
let mut share_protobuf = share_data::ShareData::new();
share_protobuf.set_shamir_data(share_data);
let b64_share = share_protobuf.write_to_bytes().unwrap().to_base64(config);
format!("{}-{}-{}", parts[0], parts[1], b64_share)
}
#[test]
fn test_recover_sellibitze() {
let share1 = "2-1-1YAYwmOHqZ69jA";
let share2 = "2-4-F7rAjX3UOa53KA";
let shares = vec![share1, share2].iter().map(|x| wrap_from_sellibitze(x)).collect::<Vec<_>>();
let mut secret = "My secret".to_string().into_bytes();
secret.push(10);
assert_eq!(recover_secret(shares, false).unwrap(), secret);
}
// Generated with code on master branch on the 6th of April.
#[test]
fn test_recover_es_test_vectors() {
let share1 =
"5-1-DbuicpLQiCf7bVWiAz8eCpQGpdZmYQ7z2j2+g351tWFLOQPTZkXY8BYfwGGGjkOoz1g9x0ScmLFcWk+2tign"
.to_string();
let share2 =
"5-2-nShdfkY5+SlfybMyqjHXCZ01bq5N/0Lkf0nQZw5x3bnHIEVfa0RA4YcJ4SjG/UdpgO/gOcyLRkSp2Dwf8bvw"
.to_string();
let share3 =
"5-3-qEhJ3IVEdbDkiRoy+jOJ/KuGE9jWyGeOYEcDwPfEV8E9rfD1Bc17BQAbJ51Xd8oexS2M1qMvNgJHZUQZbUgQ"
.to_string();
let share4 =
"5-6-yyVPUeaYPPiWK0wIV5OQ/t61V0lSEO+7X++EWeHRlIq3sRBNwUpKNfx/C+Vc9xTzUftrqBKvkWDZQal7nyi2"
.to_string();
let share5 =
"5-7-i8iL6bVf272B3qIjp0QqSny6AIm+DkP7oQjkVVLvx9EMhlvd4HJOxPpmtNF/RjA/zz21d7DY/B//saOPpBQa"
.to_string();
let shares = vec![share1, share2, share3, share4, share5]
.iter()
.map(|x| wrap_from_sellibitze(x))
.collect::<Vec<_>>();
let secret =
"The immoral cannot be made moral through the use of secret law.".to_string().into_bytes();
assert_eq!(recover_secret(shares, false).unwrap(), secret);
}
#[test]
fn test_recover_sellibitze_more_than_threshold_shars() {
let share1 = "2-1-1YAYwmOHqZ69jA".to_string();
let share2 = "2-4-F7rAjX3UOa53KA".to_string();
let share3 = "2-2-YJZQDGm22Y77Gw".to_string();
let share4 = "2-5-j0P4PHsw4lW+rg".to_string();
let shares = vec![share1, share2, share3, share4]
.iter()
.map(|x| wrap_from_sellibitze(x))
.collect::<Vec<_>>();
let mut secret = "My secret".to_string().into_bytes();
secret.push(10);
assert_eq!(recover_secret(shares, false).unwrap(), secret);
}

69
src/validation.rs Normal file
View File

@ -0,0 +1,69 @@
use custom_error::other_io_err;
use merkle_sigs::verify_data_vec_signature;
use share_format;
use share_format::format_share_for_signing;
use std::error::Error;
use std::io;
pub fn process_and_validate_shares(shares_strings: Vec<String>,
verify_signatures: bool)
-> io::Result<(u8, Vec<(u8, Vec<u8>)>)> {
let mut opt_k: Option<u8> = None;
let mut opt_root_hash: Option<Vec<u8>> = None;
let mut shares: Vec<(u8, Vec<u8>)> = Vec::new();
for (counter, line) in shares_strings.iter().enumerate() {
let (share_data, k, n, sig_pair) = try!(share_format::share_from_string(line,
verify_signatures));
if verify_signatures {
if sig_pair.is_none() {
return Err(other_io_err("Signature is missing while shares are required to be \
signed.",
None));
}
let (signature, p) = sig_pair.unwrap();
let root_hash = p.root_hash.clone();
if let Some(rh) = opt_root_hash.clone() {
if root_hash != rh {
return Err(other_io_err("Root hash not matching", None));
}
p.validate(&rh);
} else {
opt_root_hash = Some(root_hash.clone());
}
try!(verify_data_vec_signature(format_share_for_signing(k,
n,
&share_data.as_slice()),
&(signature.to_vec(), p),
&root_hash)
.map_err(|e| other_io_err("Invalid signature", Some(String::from(e.description())))));
}
if let Some(k_global) = opt_k {
if k != k_global {
return Err(other_io_err("Incompatible shares", None));
}
} else {
opt_k = Some(k);
}
if shares.iter().any(|s| s.0 == n) {
return Err(other_io_err("Duplicate Share Number", None));
};
if shares.iter().any(|s| s.1 == share_data) {
return Err(other_io_err("Duplicate Share Data", None));
};
shares.push((n, share_data));
if counter + 1 == k as usize {
return Ok((k, shares));
}
}
Err(other_io_err("Not enough shares provided!", None))
}

View File

@ -1,22 +1,11 @@
extern crate rusty_secrets;
use rusty_secrets::custom_error::{pie2io};
use rusty_secrets::generate_shares;
use std::error::Error;
#[test]
#[should_panic(expected = "Threshold K can not be larger than N")]
fn test_generate_invalid_k() {
let share1 = "2-1-1YAYwmOHqZ69jA".to_string().into_bytes();
generate_shares(10, 5, &share1).unwrap();
}
#[test]
fn test_parse_errors() {
let nan = "2a".to_string();
match nan.parse::<u8>().map_err(pie2io) {
Ok(_) => assert!(false),
Err(x) => assert_eq!("Integer parsing error", x.description()),
}
generate_shares(10, 5, share1.as_slice(), true).unwrap();
}

View File

@ -1,16 +1,25 @@
extern crate rusty_secrets;
use rusty_secrets::{recover_secret, generate_shares};
use rusty_secrets::{generate_shares, recover_secret};
#[ignore]
#[test]
fn test_reasonable_splits() {
let max_shares = 50;
let secret = String::from("I grew up with the understanding that the world I lived in was one where people enjoyed a sort of freedom to communicate with each other in privacy, without it being monitored, without it being measured or analyzed or sort of judged by these shadowy figures or systems, any time they mention anything that travels across public lines.").into_bytes();
let max_shares = 25;
let secret = "I grew up with the understanding that the world I lived in was one where people \
enjoyed a sort of freedom to communicate with each other in privacy, without it \
being monitored, without it being measured or analyzed or sort of judged by \
these shadowy figures or systems, any time they mention anything that travels \
across public lines."
.to_string()
.into_bytes();
for is_signing in vec![true, false] {
for k in 2..max_shares {
for n in k..max_shares{
let shares = generate_shares(k,n, &secret).unwrap();
for n in k..max_shares {
let shares = generate_shares(k, n, &secret, is_signing).unwrap();
println!("Testing {} out-of- {}", k, n);
assert_eq!(secret, recover_secret(shares).unwrap());
assert_eq!(secret, recover_secret(shares, is_signing).unwrap());
}
}
}
}

View File

@ -1,12 +1,12 @@
extern crate rusty_secrets;
use rusty_secrets::{recover_secret};
use rusty_secrets::recover_secret;
#[test]
#[should_panic(expected = "Not enough shares provided!")]
fn test_recover_sellibitze_no_shares() {
let shares = vec![];
recover_secret(shares).unwrap();
recover_secret(shares, false).unwrap();
}
#[test]
@ -17,7 +17,7 @@ fn test_recover_2_parts_share() {
let shares = vec![share1, share2];
recover_secret(shares).unwrap();
recover_secret(shares, false).unwrap();
}
#[test]
@ -28,7 +28,7 @@ fn test_recover_incorrect_share_num() {
let shares = vec![share1, share2];
recover_secret(shares).unwrap();
recover_secret(shares, false).unwrap();
}
#[test]
@ -39,7 +39,7 @@ fn test_recover_0_share_num() {
let shares = vec![share1, share2];
recover_secret(shares).unwrap();
recover_secret(shares, false).unwrap();
}
#[test]
@ -50,18 +50,7 @@ fn test_recover_invalid_b64() {
let shares = vec![share1, share2];
recover_secret(shares).unwrap();
}
#[test]
#[should_panic(expected = "Incompatible shares")]
fn test_recover_invalid_b64_size() {
let share1 = "2-1-CgnlCxRNtnkzENE".to_string();
let share2 = "3-5-Cgl/3sS13REq2X8".to_string();
let shares = vec![share1, share2];
recover_secret(shares).unwrap();
recover_secret(shares, false).unwrap();
}
#[test]
@ -72,7 +61,7 @@ fn test_recover_duplicate_shares_number() {
let shares = vec![share1, share2];
recover_secret(shares).unwrap();
recover_secret(shares, false).unwrap();
}
#[test]
@ -83,7 +72,7 @@ fn test_recover_duplicate_shares_data() {
let shares = vec![share1, share2];
recover_secret(shares).unwrap();
recover_secret(shares, false).unwrap();
}
#[test]
@ -94,5 +83,5 @@ fn test_recover_too_few_shares() {
let shares = vec![share1, share2];
recover_secret(shares).unwrap();
recover_secret(shares, false).unwrap();
}

View File

@ -1,66 +0,0 @@
extern crate rusty_secrets;
extern crate protobuf;
extern crate rustc_serialize as serialize;
use serialize::base64::{ self, FromBase64, ToBase64 };
use protobuf::Message;
#[cfg(test)]
use rusty_secrets::{recover_secret, ShareData};
pub fn wrap_from_sellibitze(share: &str) -> String {
let parts: Vec<_> = share.trim().split('-').collect();
let share_data = parts[2].from_base64().unwrap();
let config = base64::Config {
pad: false,
..base64::STANDARD
};
let mut share_protobuf = ShareData::new();
share_protobuf.set_shamirData(share_data);
let b64_share = share_protobuf.write_to_bytes().unwrap().to_base64(config);
format!("{}-{}-{}", parts[0], parts[1], b64_share)
}
#[test]
fn test_recover_sellibitze() {
let share1 = "2-1-1YAYwmOHqZ69jA";
let share2 = "2-4-F7rAjX3UOa53KA";
let shares = vec![share1, share2].iter().map(|x| wrap_from_sellibitze(x)).collect::<Vec<_>>();
let mut secret = "My secret".to_string().into_bytes();
secret.push(10);
assert_eq!(recover_secret(shares).unwrap(), secret);
}
// Generated with code on master branch on the 6th of April.
#[test]
fn test_recover_es_test_vectors() {
let share1 = "5-1-DbuicpLQiCf7bVWiAz8eCpQGpdZmYQ7z2j2+g351tWFLOQPTZkXY8BYfwGGGjkOoz1g9x0ScmLFcWk+2tign".to_string();
let share2 = "5-2-nShdfkY5+SlfybMyqjHXCZ01bq5N/0Lkf0nQZw5x3bnHIEVfa0RA4YcJ4SjG/UdpgO/gOcyLRkSp2Dwf8bvw".to_string();
let share3 = "5-3-qEhJ3IVEdbDkiRoy+jOJ/KuGE9jWyGeOYEcDwPfEV8E9rfD1Bc17BQAbJ51Xd8oexS2M1qMvNgJHZUQZbUgQ".to_string();
let share4 = "5-6-yyVPUeaYPPiWK0wIV5OQ/t61V0lSEO+7X++EWeHRlIq3sRBNwUpKNfx/C+Vc9xTzUftrqBKvkWDZQal7nyi2".to_string();
let share5 = "5-7-i8iL6bVf272B3qIjp0QqSny6AIm+DkP7oQjkVVLvx9EMhlvd4HJOxPpmtNF/RjA/zz21d7DY/B//saOPpBQa".to_string();
let shares = vec![share1, share2, share3, share4, share5].iter().map(|x| wrap_from_sellibitze(x)).collect::<Vec<_>>();
let secret = "The immoral cannot be made moral through the use of secret law.".to_string().into_bytes();
assert_eq!(recover_secret(shares).unwrap(), secret);
}
#[test]
fn test_recover_sellibitze_more_than_threshold_shars() {
let share1 = "2-1-1YAYwmOHqZ69jA".to_string();
let share2 = "2-4-F7rAjX3UOa53KA".to_string();
let share3 = "2-2-YJZQDGm22Y77Gw".to_string();
let share4 = "2-5-j0P4PHsw4lW+rg".to_string();
let shares = vec![share1, share2, share3, share4].iter().map(|x| wrap_from_sellibitze(x)).collect::<Vec<_>>();
let mut secret = "My secret".to_string().into_bytes();
secret.push(10);
assert_eq!(recover_secret(shares).unwrap(), secret);
}