Digest-Bcrypt-1.212000755001750001750 014171076345 15352 5ustar00cwhitenercwhitener000000000000README100755001750001750 1655014171076345 16345 0ustar00cwhitenercwhitener000000000000Digest-Bcrypt-1.212NAME Digest::Bcrypt - Perl interface to the bcrypt digest algorithm SYNOPSIS #!/usr/bin/env perl use strict; use warnings; use utf8; use Digest; # via the Digest module (recommended) my $bcrypt = Digest->new('Bcrypt', cost => 12, salt => 'abcdefgh♥stuff'); # You can forego the cost and salt in favor of settings strings: my $bcrypt = Digest->new('Bcrypt', settings => '$2a$20$GA.eY03tb02ea0DqbA.eG.'); # $cost is an integer between 5 and 31 $bcrypt->cost(12); # $type is a selection between 2a, 2b, 2x, and 2y $bcrypt->type('2b'); # $salt must be exactly 16 octets long $bcrypt->salt('abcdefgh♥stuff'); # OR, for good, random salts: use Data::Entropy::Algorithms qw(rand_bits); $bcrypt->salt(rand_bits(16*8)); # 16 octets # You can forego the cost and salt in favor of settings strings: $bcrypt->settings('$2a$20$GA.eY03tb02ea0DqbA.eG.'); # add some strings we want to make a secret of $bcrypt->add('some stuff', 'here and', 'here'); my $digest = $bcrypt->digest; $digest = $bcrypt->hexdigest; $digest = $bcrypt->b64digest; # bcrypt's own non-standard base64 dictionary $digest = $bcrypt->bcrypt_b64digest; # Now, let's create a password hash and check it later: use Data::Entropy::Algorithms qw(rand_bits); my $bcrypt = Digest->new('Bcrypt', type => '2b', cost => 20, salt => rand_bits(16*8)); my $settings = $bcrypt->settings(); # save for later checks. my $pass_hash = $bcrypt->add('Some secret password')->digest; # much later, we can check a password against our hash via: my $bcrypt = Digest->new('Bcrypt', settings => $settings); if ($bcrypt->add($value_from_user)->digest eq $known_pass_hash) { say "Your password matched"; } else { say "Try again!"; } # Now that you've seen how cumbersome/silly that is, # please use Crypt::Bcrypt instead of this module. NOTICE While maintenance for Digest::Bcrypt will continue, there's no reason to use Digest::Bcrypt when Crypt::Bcrypt already exists. We strongly suggest that you use Crypt::Bcrypt instead. This "Digest::Bcrypt" interface is crufty and laborious to use when compared to that of Crypt::Bcrypt. DESCRIPTION Digest::Bcrypt provides a Digest-based interface to the Crypt::Bcrypt library. Please note that you must set a "salt" of exactly 16 octets in length, and you must provide a "cost" in the range 1..31. ATTRIBUTES Digest::Bcrypt implements the following attributes. cost $bcrypt = $bcrypt->cost(20); # allows for method chaining my $cost = $bcrypt->cost(); An integer in the range 5..31, this is required. See Crypt::Eksblowfish::Bcrypt for a detailed description of "cost" in the context of the bcrypt algorithm. When called with no arguments, it will return the current cost. salt $bcrypt = $bcrypt->salt('abcdefgh♥stuff'); # allows for method chaining my $salt = $bcrypt->salt(); # OR, for good, random salts: use Data::Entropy::Algorithms qw(rand_bits); $bcrypt->salt(rand_bits(16*8)); # 16 octets Sets the value to be used as a salt. Bcrypt requires exactly 16 octets of salt. It is recommenced that you use a module like Data::Entropy::Algorithms to provide a truly randomized salt. When called with no arguments, it will return the current salt. settings $bcrypt = $bcrypt->settings('$2a$20$GA.eY03tb02ea0DqbA.eG.'); # allows for method chaining my $settings = $bcrypt->settings(); A "settings" string can be used to set the "salt" in Digest::Bcrypt and "cost" in Digest::Bcrypt automatically. Setting the "settings" will override any current values in your "cost" and "salt" attributes. For details on the "settings" string requirements, please see Crypt::Eksblowfish::Bcrypt. When called with no arguments, it will return the current settings string. type $bcrypt = $bcrypt->type('2b'); # method chaining on mutations say $bcrypt->type(); # 2b This sets the subtype of bcrypt used. These subtypes are as defined in Crypt::Bcrypt. The available types are: "2b" which is the current standard, "2a" which is older; it's the one used in Crypt::Eksblowfish, "2y" which is considered equivalent to "2b" and used in PHP. "2x" which is very broken and only needed to work with ancient PHP versions. METHODS Digest::Bcrypt inherits all methods from Digest::base and implements/overrides the following methods as well. new my $bcrypt = Digest->new('Bcrypt', %params); my $bcrypt = Digest::Bcrypt->new(%params); my $bcrypt = Digest->new('Bcrypt', \%params); my $bcrypt = Digest::Bcrypt->new(\%params); Creates a new "Digest::Bcrypt" object. It is recommended that you use the Digest module in the first example rather than using Digest::Bcrypt directly. Any of the "ATTRIBUTES" in Digest::Bcrypt above can be passed in as a parameter. add $bcrypt->add("a"); $bcrypt->add("b"); $bcrypt->add("c"); $bcrypt->add("a")->add("b")->add("c"); $bcrypt->add("a", "b", "c"); $bcrypt->add("abc"); Adds data to the message we are calculating the digest for. All the above examples have the same effect. b64digest my $digest = $bcrypt->b64digest; Same as "digest", but will return the digest base64 encoded. The "length" of the returned string will be 31 and will only contain characters from the ranges '0'..'9', 'A'..'Z', 'a'..'z', '+', and '/' The base64 encoded string returned is not padded to be a multiple of 4 bytes long. bcrypt_b64digest my $digest = $bcrypt->bcrypt_b64digest; Same as "digest", but will return the digest base64 encoded using the alphabet that is commonly used with bcrypt. The "length" of the returned string will be 31 and will only contain characters from the ranges '0'..'9', 'A'..'Z', 'a'..'z', '+', and '.' The base64 encoded string returned is not padded to be a multiple of 4 bytes long. *Note:* This is bcrypt's own non-standard base64 alphabet, It is not compatible with the standard MIME base64 encoding. clone my $clone = $bcrypt->clone; Creates a clone of the "Digest::Bcrypt" object, and returns it. digest my $digest = $bcrypt->digest; Returns the binary digest for the message. The returned string will be 23 bytes long. hexdigest my $digest = $bcrypt->hexdigest; Same as "digest", but will return the digest in hexadecimal form. The "length" of the returned string will be 46 and will only contain characters from the ranges '0'..'9' and 'a'..'f'. reset $bcrypt->reset; Resets the object to the same internal state it was in when it was constructed. SEE ALSO Digest, Crypt::Eksblowfish::Bcrypt, Data::Entropy::Algorithms AUTHOR James Aitken "jaitken@cpan.org" CONTRIBUTORS * Chase Whitener "capoeira@cpan.org" COPYRIGHT AND LICENSE This software is copyright (c) 2012 by James Aitken. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Changes100755001750001750 750514171076345 16740 0ustar00cwhitenercwhitener000000000000Digest-Bcrypt-1.212Revision history for Digest-Bcrypt 1.212 2022-01-16 - Remove specific cost size restrictions and let those be determined by Crypt::Bcrypt (thanks, Aaron Hall: GH#7) 1.211 2022-01-12 - Fixed some typos and organization of documentation - Ensured all code was run through perltidy - Get rid of TravisCI config - Add some more guidance about not using this module - Fix syntax use that broke compatibility with 5.8 - Setup GH Workflows for testing 1.210 2022-01-10 - Update to Starter::Git and clean up the dist.ini file - Switch to Crypt::Bcrypt - Change all tests to use a cost of 5 at least - Add a 'type' attribute so selecting the encoding type is possible - Default the type to 2a to keep it as it was prior to switching to Crypt::Bcrypt 1.209 2017-03-25 - Revert to using bytes as that broke salt length tests - Added a few author tests for Data::Entropy::Algorithms::rand_bits() 1.208 2017-03-24 - Remove MANIFEST.SKIP as we use .gitignore - Stop using 'bytes' and make use of Encode instead as we're already on at least version 5.8.1 - Remove Try::Tiny from runtime requirements as it's only used in testing 1.207 2017-02-11 - Added LICENSE and CONTRIBUTING.md files - Added settings attribute - Added documentation on how best to create a salt - Added some extra doc examples 1.206 2016-07-01 - Fix errant inclusions in cpanfile 1.205 2016-06-06 - Put requirements in a cpanfile - Changed to [Starter] 1.204 2016-03-21 - moved to Dist::Zilla - perltidy'd everything 1.203 2016-03-07 [ TESTS ] * Fixed test reliant upon Perl error messages 1.202 2016-03-05 [ FEATURE ] * Allowed the constructor to accept a hashref or a hash as requested in issue #1 [ TESTS ] * Added many more tests to the suite [ DOCUMENTATION ] * Updated the documentation to show the ability to add parameters to the constructor. * Moved cost and salt descriptions to a new "attributes" section. 1.201 2016-03-05 [ DOCUMENTATION ] * Added a blurb to use Crypt::Eksblowfish::Bcrypt instead [ BUILD ] * Made the build a bit more generic [ TESTS ] * Alleviated some of the issues taking lots of TravisCI time 1.200_001 2016-03-02 [ DOCUMENTATION ] * fixed typos * organized methods by constructor, then alphabetical * showed more in-depth examples of how to use the methods * moved example code to the SYNOPSIS section * made a DESCRIPTION section * added Chase Whitener as current maintainer [ TESTS ] * Changed to use Try::Tiny instead of raw eval 1.0.2 2013-01-23 [ TESTS ] * Module is now tested by Travis CI 1.0.1 2012-04-07 [ BUGFIX ] * $VERSION was not incremented in previous release. 1.0.0 2012-04-07 [ BUGFIX ] * Remove accidental dependency on perl 5.10 introduced in previous revision [ FEATURE ] * bcrypt_b64digest method added to return digest base64 encoded using the base 64 alphabet commonly used with bcrypt * b64digest method now returns a base64 that is compatible with the standard MIME alphabet. To access the version of base64 commonly used with bcrypt, use the new bcrypt_b64digest method This is a backwards incompatible change [ TESTS ] * Added additional tests for new methods 0.1.1 2012-04-05 [ DOCUMENTATION ] * Fixed typos in base64 method description [ FEATURE ] * Improved handling of cases where the cost / salt methods have never been called [ TESTS ] * Improved error handling tests 0.1.0 2012-03-31 ** First Public Release ** [ DOCUMENTATION ] * Added Documentation [ TESTS ] * Added Test Suite 0.0.1 2011-03-30 ** First Draft ** LICENSE100755001750001750 4365014171076345 16473 0ustar00cwhitenercwhitener000000000000Digest-Bcrypt-1.212This software is copyright (c) 2012 by James Aitken. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2012 by James Aitken. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2012 by James Aitken. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End cpanfile100755001750001750 125114171076345 17141 0ustar00cwhitenercwhitener000000000000Digest-Bcrypt-1.212on 'runtime' => sub { requires 'perl' => '5.008001'; requires 'strict'; requires 'warnings'; requires 'bytes'; requires 'parent'; requires 'utf8'; requires 'Carp'; requires 'Crypt::Bcrypt'; requires 'Digest'; requires 'MIME::Base64'; }; on 'test' => sub { requires 'Scalar::Util' => '0.88'; requires 'Test::More' => '0.88'; requires 'Try::Tiny' => '0.24'; }; on 'develop' => sub { requires 'Data::Entropy::Algorithms'; requires 'Test::CheckManifest' => '1.29'; requires 'Test::CPAN::Changes' => '0.4'; requires 'Test::Kwalitee' => '1.22'; requires 'Test::Pod::Spelling::CommonMistakes' => '1.000'; }; dist.ini100755001750001750 200114171076345 17073 0ustar00cwhitenercwhitener000000000000Digest-Bcrypt-1.212name = Digest-Bcrypt author = James Aitken license = Perl_5 copyright_holder = James Aitken copyright_year = 2012 ; version = 1.210 [ReadmeAnyFromPod / Markdown_Readme] type = gfm source_filename = lib/Digest/Bcrypt.pm filename = README.md location = root [Regenerate::AfterReleasers] plugin = Markdown_Readme [@Starter::Git] revision = 5 managed_versions = 1 installer = MakeMaker::Awesome RewriteVersion.global = 1 NextRelease.format = %-9v %{yyyy-MM-dd}d Test::Compile.xt_mode = 1 regenerate = Makefile.PL regenerate = META.json regenerate = README.md regenerate = LICENSE regenerate = t/00-report-prereqs.t Git::Check.allow_dirty = META.json [Prereqs::FromCPANfile] [Git::Contributors] [GithubMeta] issues = 1 user = genio [CheckChangeLog] [CheckChangesHasContent] [Test::ChangesHasContent] [Test::Kwalitee] [Test::Version] [Test::Pod::Coverage::Configurable] [Test::PodSpelling] wordlist = Pod::Wordlist spell_cmd = aspell list stopword = Aitken stopword = hexdigest META.yml100755001750001750 237114171076345 16712 0ustar00cwhitenercwhitener000000000000Digest-Bcrypt-1.212--- abstract: 'Perl interface to the bcrypt digest algorithm' author: - 'James Aitken ' build_requires: ExtUtils::MakeMaker: '0' File::Spec: '0' Scalar::Util: '0.88' Test::More: '0.88' Try::Tiny: '0.24' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 0 generated_by: 'Dist::Zilla version 6.024, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Digest-Bcrypt no_index: directory: - eg - examples - inc - share - t - xt provides: Digest::Bcrypt: file: lib/Digest/Bcrypt.pm version: '1.212' requires: Carp: '0' Crypt::Bcrypt: '0' Digest: '0' MIME::Base64: '0' bytes: '0' parent: '0' perl: '5.008001' strict: '0' utf8: '0' warnings: '0' resources: bugtracker: https://github.com/genio/digest-bcrypt/issues homepage: https://github.com/genio/digest-bcrypt repository: https://github.com/genio/digest-bcrypt.git version: '1.212' x_contributors: - 'Chase Whitener ' - 'James Aitken ' x_generated_by_perl: v5.30.0 x_serialization_backend: 'YAML::Tiny version 1.73' x_spdx_expression: 'Artistic-1.0-Perl OR GPL-1.0-or-later' MANIFEST100755001750001750 100414171076345 16562 0ustar00cwhitenercwhitener000000000000Digest-Bcrypt-1.212# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.024. CONTRIBUTING.md Changes LICENSE MANIFEST META.json META.yml Makefile.PL README cpanfile dist.ini lib/Digest/Bcrypt.pm t/00-report-prereqs.dd t/00-report-prereqs.t t/001_basics.t t/002_methods.t t/003_create_digests.t t/004_error_handling.t xt/author/00-compile.t xt/author/pod-coverage.t xt/author/pod-spell.t xt/author/pod-syntax.t xt/author/rand_bits.t xt/author/test-version.t xt/release/changes_has_content.t xt/release/kwalitee.t META.json100755001750001750 542314171076345 17063 0ustar00cwhitenercwhitener000000000000Digest-Bcrypt-1.212{ "abstract" : "Perl interface to the bcrypt digest algorithm", "author" : [ "James Aitken " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 6.024, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Digest-Bcrypt", "no_index" : { "directory" : [ "eg", "examples", "inc", "share", "t", "xt" ] }, "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "develop" : { "requires" : { "Data::Entropy::Algorithms" : "0", "File::Spec" : "0", "IO::Handle" : "0", "IPC::Open3" : "0", "Pod::Coverage::TrustPod" : "0", "Test::CPAN::Changes" : "0.4", "Test::CheckManifest" : "1.29", "Test::Kwalitee" : "1.22", "Test::More" : "0.88", "Test::Pod" : "1.41", "Test::Pod::Coverage" : "1.08", "Test::Pod::Spelling::CommonMistakes" : "1.000", "Test::Spelling" : "0.12", "Test::Version" : "1" } }, "runtime" : { "requires" : { "Carp" : "0", "Crypt::Bcrypt" : "0", "Digest" : "0", "MIME::Base64" : "0", "bytes" : "0", "parent" : "0", "perl" : "5.008001", "strict" : "0", "utf8" : "0", "warnings" : "0" } }, "test" : { "recommends" : { "CPAN::Meta" : "2.120900" }, "requires" : { "ExtUtils::MakeMaker" : "0", "File::Spec" : "0", "Scalar::Util" : "0.88", "Test::More" : "0.88", "Try::Tiny" : "0.24" } } }, "provides" : { "Digest::Bcrypt" : { "file" : "lib/Digest/Bcrypt.pm", "version" : "1.212" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/genio/digest-bcrypt/issues" }, "homepage" : "https://github.com/genio/digest-bcrypt", "repository" : { "type" : "git", "url" : "https://github.com/genio/digest-bcrypt.git", "web" : "https://github.com/genio/digest-bcrypt" } }, "version" : "1.212", "x_contributors" : [ "Chase Whitener ", "James Aitken " ], "x_generated_by_perl" : "v5.30.0", "x_serialization_backend" : "Cpanel::JSON::XS version 4.27", "x_spdx_expression" : "Artistic-1.0-Perl OR GPL-1.0-or-later" } Makefile.PL100755001750001750 312114171076345 17405 0ustar00cwhitenercwhitener000000000000Digest-Bcrypt-1.212# This Makefile.PL for Digest-Bcrypt was generated by # Dist::Zilla::Plugin::MakeMaker::Awesome 0.49. # Don't edit it but the dist.ini and plugins used to construct it. use strict; use warnings; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "Perl interface to the bcrypt digest algorithm", "AUTHOR" => "James Aitken ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "Digest-Bcrypt", "LICENSE" => "perl", "NAME" => "Digest::Bcrypt", "PREREQ_PM" => { "Carp" => 0, "Crypt::Bcrypt" => 0, "Digest" => 0, "MIME::Base64" => 0, "bytes" => 0, "parent" => 0, "strict" => 0, "utf8" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "ExtUtils::MakeMaker" => 0, "File::Spec" => 0, "Scalar::Util" => "0.88", "Test::More" => "0.88", "Try::Tiny" => "0.24" }, "VERSION" => "1.212", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Carp" => 0, "Crypt::Bcrypt" => 0, "Digest" => 0, "ExtUtils::MakeMaker" => 0, "File::Spec" => 0, "MIME::Base64" => 0, "Scalar::Util" => "0.88", "Test::More" => "0.88", "Try::Tiny" => "0.24", "bytes" => 0, "parent" => 0, "strict" => 0, "utf8" => 0, "warnings" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION('6.63_03') } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); t000755001750001750 014171076345 15536 5ustar00cwhitenercwhitener000000000000Digest-Bcrypt-1.212001_basics.t100755001750001750 2525014171076345 17736 0ustar00cwhitenercwhitener000000000000Digest-Bcrypt-1.212/tuse strict; use warnings; use Test::More; use Try::Tiny qw(try catch); BEGIN { use_ok 'Digest' || BAIL_OUT("Can't use Digest"); use_ok 'Digest::Bcrypt' || BAIL_OUT("Can't use Digest::Bcrypt"); } can_ok('Digest::Bcrypt', qw(new add bcrypt_b64digest clone cost hexdigest salt settings digest reset) ); my $salt = " known salt "; my $settings = '$2a$20$GA.eY03tb02ea0DqbA.eG.'; # new instance, no params { my $db = try { Digest::Bcrypt->new(); } catch { return "Couldn't create instance: $_"; }; isa_ok($db, 'Digest::Bcrypt', 'new: no params'); } # new instance, empty hashref { my $db = try { Digest::Bcrypt->new({}); } catch { return "Couldn't create instance: $_"; }; isa_ok($db, 'Digest::Bcrypt', 'new: empty hashref'); } # new instance, cost as hash { my $db = try { Digest::Bcrypt->new(cost => 20); } catch { return "Couldn't create instance: $_"; }; isa_ok($db, 'Digest::Bcrypt', 'new: hash with cost 20'); is($db->cost(), 20, 'cost: correct value of 20'); } # new instance, cost as hashref { my $db = try { Digest::Bcrypt->new({cost => 20}); } catch { return "Couldn't create instance: $_"; }; isa_ok($db, 'Digest::Bcrypt', 'new: hashref with cost 20'); is($db->cost(), 20, 'cost: correct value of 20'); } # new instance, salt as hash { my $db = try { Digest::Bcrypt->new(salt => $salt); } catch { return "Couldn't create instance: $_"; }; isa_ok($db, 'Digest::Bcrypt', 'new: hash with salt'); is($db->salt(), $salt, 'salt: correct value'); } # new instance, salt as hashref { my $db = try { Digest::Bcrypt->new({salt => $salt}); } catch { return "Couldn't create instance: $_"; }; isa_ok($db, 'Digest::Bcrypt', 'new: hashref with salt'); is($db->salt(), $salt, 'salt: correct value'); } # new instance, settings as hash { my $db = try { Digest::Bcrypt->new(settings => $settings); } catch { return "Couldn't create instance: $_"; }; isa_ok($db, 'Digest::Bcrypt', 'new: hash with settings'); is($db->settings(), $settings, 'settings: correct value'); } # new instance, settings as hashref { my $db = try { Digest::Bcrypt->new({settings => $settings}); } catch { return "Couldn't create instance: $_"; }; isa_ok($db, 'Digest::Bcrypt', 'new: hashref with settings'); is($db->settings(), $settings, 'settings: correct value'); } # new instance, cost and salt as hash { my $db = try { Digest::Bcrypt->new(cost => 20, salt => $salt); } catch { return "Couldn't create instance: $_"; }; isa_ok($db, 'Digest::Bcrypt', 'new: hash with cost and salt'); is($db->cost(), 20, 'cost: correct value'); is($db->salt(), $salt, 'salt: correct value'); } # new instance, cost and salt as hashref { my $db = try { Digest::Bcrypt->new({cost => 20, salt => $salt}); } catch { return "Couldn't create instance: $_"; }; isa_ok($db, 'Digest::Bcrypt', 'new: hashref with cost and salt'); is($db->cost(), 20, 'cost: correct value'); is($db->salt(), $salt, 'salt: correct value'); } # new instance, cost and salt and settings as hash { my $db = try { Digest::Bcrypt->new( cost => 22, salt => ' ', settings => $settings ); } catch { return "Couldn't create instance: $_"; }; isa_ok($db, 'Digest::Bcrypt', 'new: hash with cost and salt and settings'); is($db->cost(), 20, 'cost: correct value'); is($db->salt(), $salt, 'salt: correct value'); is($db->settings(), $settings, 'settings: correct value'); } # new instance, cost and salt and settings hashref { my $db = try { Digest::Bcrypt->new( {cost => 22, salt => ' ', settings => $settings}); } catch { return "Couldn't create instance: $_"; }; isa_ok($db, 'Digest::Bcrypt', 'new: hashref with cost and salt and settings'); is($db->cost(), 20, 'cost: correct value'); is($db->salt(), $salt, 'salt: correct value'); is($db->settings(), $settings, 'settings: correct value'); } # new instance, empty string { my $db = try { Digest::Bcrypt->new(''); } catch { return "Couldn't create instance: $_"; }; like($db, qr/^Couldn't create instance:/, 'new: failed with empty string'); } # new instance, undef value { my $db = try { Digest::Bcrypt->new(undef); } catch { return "Couldn't create instance: $_"; }; like($db, qr/^Couldn't create instance:/, 'new: failed with undef value'); } # new instance, deal with cost { my $err = try { my $db = Digest::Bcrypt->new(); $db->cost(20); is($db->cost(), 20, 'cost: properly set to 20'); $db->cost(undef); is($db->cost(), undef, 'cost: properly set to undef'); return ''; } catch { return "Error: $_"; }; is($err, '', 'cost: no errors trapped'); } # new instance, deal with salt { my $err = try { my $db = Digest::Bcrypt->new(); $db->salt($salt); is($db->salt(), $salt, 'salt: properly set to 20'); $db->salt(undef); is($db->salt(), undef, 'salt: properly set to undef'); return ''; } catch { return "Error: $_"; }; is($err, '', 'salt: no errors trapped'); } # new instance, no params { my $db = try { Digest->new('Bcrypt'); } catch { return "Couldn't create instance: $_"; }; isa_ok($db, 'Digest::Bcrypt', 'new: no params'); } # new instance, empty hashref { my $db = try { Digest->new('Bcrypt', {}); } catch { return "Couldn't create instance: $_"; }; isa_ok($db, 'Digest::Bcrypt', 'new: empty hashref'); } # new instance, cost as hash { my $db = try { Digest->new('Bcrypt', cost => 20); } catch { return "Couldn't create instance: $_"; }; isa_ok($db, 'Digest::Bcrypt', 'new: hash with cost 20'); is($db->cost(), 20, 'cost: correct value of 20'); } # new instance, cost as hashref { my $db = try { Digest->new('Bcrypt', {cost => 20}); } catch { return "Couldn't create instance: $_"; }; isa_ok($db, 'Digest::Bcrypt', 'new: hashref with cost 20'); is($db->cost(), 20, 'cost: correct value of 20'); } # new instance, salt as hash { my $db = try { Digest->new('Bcrypt', salt => $salt); } catch { return "Couldn't create instance: $_"; }; isa_ok($db, 'Digest::Bcrypt', 'new: hash with salt'); is($db->salt(), $salt, 'salt: correct value'); } # new instance, salt as hashref { my $db = try { Digest->new('Bcrypt', {salt => $salt}); } catch { return "Couldn't create instance: $_"; }; isa_ok($db, 'Digest::Bcrypt', 'new: hashref with salt'); is($db->salt(), $salt, 'salt: correct value'); } # new instance, settings as hash { my $db = try { Digest->new('Bcrypt', settings => $settings); } catch { return "Couldn't create instance: $_"; }; isa_ok($db, 'Digest::Bcrypt', 'new: hash with settings'); is($db->settings(), $settings, 'settings: correct value'); } # new instance, settings as hashref { my $db = try { Digest->new('Bcrypt', {settings => $settings}); } catch { return "Couldn't create instance: $_"; }; isa_ok($db, 'Digest::Bcrypt', 'new: hashref with settings'); is($db->settings(), $settings, 'settings: correct value'); } # new instance, cost and salt as hash { my $db = try { Digest->new('Bcrypt', cost => 20, salt => $salt); } catch { return "Couldn't create instance: $_"; }; isa_ok($db, 'Digest::Bcrypt', 'new: hash with cost and salt'); is($db->cost(), 20, 'cost: correct value'); is($db->salt(), $salt, 'salt: correct value'); } # new instance, cost and salt as hashref { my $db = try { Digest->new('Bcrypt', {cost => 20, salt => $salt}); } catch { return "Couldn't create instance: $_"; }; isa_ok($db, 'Digest::Bcrypt', 'new: hashref with cost and salt'); is($db->cost(), 20, 'cost: correct value'); is($db->salt(), $salt, 'salt: correct value'); } # new instance, cost and salt and settings as hash { my $db = try { Digest->new( 'Bcrypt', cost => 22, salt => ' ', settings => $settings ); } catch { return "Couldn't create instance: $_"; }; isa_ok($db, 'Digest::Bcrypt', 'new: hash with cost and salt and settings'); is($db->cost(), 20, 'cost: correct value'); is($db->salt(), $salt, 'salt: correct value'); is($db->settings(), $settings, 'settings: correct value'); } # new instance, cost and salt and settings as hashref { my $db = try { Digest->new('Bcrypt', {cost => 22, salt => ' ', settings => $settings}); } catch { return "Couldn't create instance: $_"; }; isa_ok($db, 'Digest::Bcrypt', 'new: hashref with cost and salt and settings'); is($db->cost(), 20, 'cost: correct value'); is($db->salt(), $salt, 'salt: correct value'); is($db->settings(), $settings, 'settings: correct value'); } # new instance, empty string { my $db = try { Digest->new('Bcrypt', ''); } catch { return "Couldn't create instance: $_"; }; like($db, qr/^Couldn't create instance:/, 'new: failed with empty string'); } # new instance, undef value { my $db = try { Digest->new('Bcrypt', undef); } catch { return "Couldn't create instance: $_"; }; like($db, qr/^Couldn't create instance:/, 'new: failed with undef value'); } # new instance, deal with cost { my $err = try { my $db = Digest->new('Bcrypt'); $db->cost(20); is($db->cost(), 20, 'cost: properly set to 20'); $db->cost(undef); is($db->cost(), undef, 'cost: properly set to undef'); return ''; } catch { return "Error: $_"; }; is($err, '', 'cost: no errors trapped'); } # new instance, deal with salt { my $err = try { my $db = Digest->new('Bcrypt'); $db->salt($salt); is($db->salt(), $salt, 'salt: properly set to 20'); $db->salt(undef); is($db->salt(), undef, 'salt: properly set to undef'); return ''; } catch { return "Error: $_"; }; is($err, '', 'salt: no errors trapped'); } done_testing(); CONTRIBUTING.md100755001750001750 1020414171076345 17704 0ustar00cwhitenercwhitener000000000000Digest-Bcrypt-1.212# HOW TO CONTRIBUTE Thank you for considering contributing to this distribution. This file contains instructions that will help you work with the source code. The distribution is managed with [Dist::Zilla](https://metacpan.org/pod/Dist::Zilla). This means that many of the usual files you might expect are not in the repository, but are generated at release time. Some generated files are kept in the repository as a convenience (e.g. Build.PL/Makefile.PL and META.json). Generally, **you do not need Dist::Zilla to contribute patches**. You may need Dist::Zilla to create a tarball. See below for guidance. ## Getting dependencies If you have App::cpanminus 1.6 or later installed, you can use [cpanm](https://metacpan.org/pod/cpanm) to satisfy dependencies like this: $ cpanm --installdeps --with-develop . You can also run this command (or any other cpanm command) without installing App::cpanminus first, using the fatpacked `cpanm` script via curl or wget: $ curl -L https://cpanmin.us | perl - --installdeps --with-develop . $ wget -qO - https://cpanmin.us | perl - --installdeps --with-develop . Otherwise, look for either a `cpanfile` or `META.json` file for a list of dependencies to satisfy. ## Running tests You can run tests directly using the `prove` tool: $ prove -l $ prove -lv t/some_test_file.t For most of my distributions, `prove` is entirely sufficient for you to test any patches you have. I use `prove` for 99% of my testing during development. ## Code style and tidying Please try to match any existing coding style. If there is a `.perltidyrc` file, please install Perl::Tidy and use perltidy before submitting patches. ## Installing and using Dist::Zilla [Dist::Zilla](https://metacpan.org/pod/Dist::Zilla) is a very powerful authoring tool, optimized for maintaining a large number of distributions with a high degree of automation, but it has a large dependency chain, a bit of a learning curve and requires a number of author-specific plugins. To install it from CPAN, I recommend one of the following approaches for the quickest installation: # using CPAN.pm, but bypassing non-functional pod tests $ cpan TAP::Harness::Restricted $ PERL_MM_USE_DEFAULT=1 HARNESS_CLASS=TAP::Harness::Restricted cpan Dist::Zilla # using cpanm, bypassing *all* tests $ cpanm -n Dist::Zilla In either case, it's probably going to take about 10 minutes. Go for a walk, go get a cup of your favorite beverage, take a bathroom break, or whatever. When you get back, Dist::Zilla should be ready for you. Then you need to install any plugins specific to this distribution: $ dzil authordeps --missing | cpanm You can use Dist::Zilla to install the distribution's dependencies if you haven't already installed them with cpanm: $ dzil listdeps --missing --develop | cpanm Once everything is installed, here are some dzil commands you might try: $ dzil build $ dzil test $ dzil regenerate You can learn more about Dist::Zilla at http://dzil.org/ ## Other notes This distribution maintains the generated `META.json` and either `Makefile.PL` or `Build.PL` in the repository. This allows two things: [Travis CI](https://travis-ci.org/) can build and test the distribution without requiring Dist::Zilla, and the distribution can be installed directly from Github or a local git repository using `cpanm` for testing (again, not requiring Dist::Zilla). $ cpanm git://github.com/Author/Distribution-Name.git $ cd Distribution-Name; cpanm . Contributions are preferred in the form of a Github pull request. See [Using pull requests](https://help.github.com/articles/using-pull-requests/) for further information. You can use the Github issue tracker to report issues without an accompanying patch. # CREDITS This file was adapted from an initial `CONTRIBUTING.mkdn` file from David Golden under the terms of the Apache 2 license, with inspiration from the contributing documents from [Dist::Zilla::Plugin::Author::KENTNL::CONTRIBUTING](https://metacpan.org/pod/Dist::Zilla::Plugin::Author::KENTNL::CONTRIBUTING) and [Dist::Zilla::PluginBundle::Author::ETHER](https://metacpan.org/pod/Dist::Zilla::PluginBundle::Author::ETHER). 002_methods.t100755001750001750 437214171076345 20120 0ustar00cwhitenercwhitener000000000000Digest-Bcrypt-1.212/tuse strict; use warnings; use Digest; use Digest::Bcrypt; use Scalar::Util qw(refaddr); use Test::More; use Try::Tiny qw(try catch); my $secret = "Super Secret Squirrel"; my $salt = " known salt "; my $cost = 5; # direct object { my $direct = Digest::Bcrypt->new; isa_ok($direct, 'Digest::Bcrypt', 'new: direct instance'); try { $direct->add($secret); $direct->salt($salt); $direct->cost($cost); } catch { fail("direct instance: $_"); }; is($direct->salt, $salt, "direct: salt correct"); is($direct->cost, "0$cost", "direct: cost correct"); my $direct_clone = $direct->clone; isa_ok($direct_clone, 'Digest::Bcrypt', 'clone: direct instance'); isnt(refaddr $direct, refaddr $direct_clone, "clone: not the same object"); try { $direct_clone->salt(' unknown salt '); $direct_clone->cost(6); } catch { fail("direct clone: $_"); }; isnt($direct->salt, $direct_clone->salt, "clone: salt differs from orig"); isnt($direct->cost, $direct_clone->cost, "clone: cost differs from orig"); isnt($direct->hexdigest, $direct_clone->hexdigest, "clone: different hash"); } # indirect object { my $indirect = Digest->new('Bcrypt'); isa_ok($indirect, 'Digest::Bcrypt', 'new: indirect instance'); try { $indirect->add($secret); $indirect->salt($salt); $indirect->cost($cost); } catch { fail("indirect instance: $_"); }; is($indirect->salt, $salt, "indirect: salt correct"); is($indirect->cost, "0$cost", "indirect: cost correct"); my $indirect_clone = $indirect->clone; isa_ok($indirect_clone, 'Digest::Bcrypt', 'clone: indirect instance'); isnt( refaddr $indirect, refaddr $indirect_clone, "clone: not the same object" ); try { $indirect_clone->salt(' unknown salt '); $indirect_clone->cost(6); } catch { fail("indirect clone: $_"); }; isnt($indirect->salt, $indirect_clone->salt, "clone: salt differs from orig"); isnt($indirect->cost, $indirect_clone->cost, "clone: cost differs from orig"); isnt( $indirect->hexdigest, $indirect_clone->hexdigest, "clone: different hash" ); } done_testing(); Digest000755001750001750 014171076345 17260 5ustar00cwhitenercwhitener000000000000Digest-Bcrypt-1.212/libBcrypt.pm100755001750001750 2607614171076345 21257 0ustar00cwhitenercwhitener000000000000Digest-Bcrypt-1.212/lib/Digestpackage Digest::Bcrypt; use parent 'Digest::base'; use strict; use warnings; require bytes; use Carp (); use Crypt::Bcrypt qw(bcrypt bcrypt_check); use MIME::Base64 qw(decode_base64 encode_base64); use utf8; our $VERSION = '1.212'; sub add { my $self = shift; $self->{_buffer} .= join('', @_); return $self; } sub bcrypt_b64digest { my $encoded = encode_base64(shift->digest, ""); $encoded =~ tr{A-Za-z0-9+/=}{./A-Za-z0-9}d; return $encoded; } sub clone { my $self = shift; return undef unless my $clone = $self->new( cost => $self->cost, salt => $self->salt, type => $self->type, ); $clone->add($self->{_buffer}); return $clone; } sub cost { my $self = shift; return $self->{cost} unless @_; my $cost = shift; # allow and undefined value to clear it unless (defined $cost) { delete $self->{cost}; return $self; } $self->_check_cost($cost); # bcrypt requires 2 digit costs, it dies if it's a single digit. $self->{cost} = sprintf("%02d", $cost); return $self; } sub digest { my $self = shift; $self->_check_cost; $self->_check_salt; my $type = defined($self->{type}) ? $self->{type} : '2a'; my $hash = bcrypt($self->{_buffer}, $type, $self->cost, $self->salt); my $settings = $self->settings; $self->reset; return _de_base64(substr($hash, length($settings))); } # new isn't actually implemented in the base class. eww. sub new { my $class = shift; my $self = bless {_buffer => '',}, ref $class || $class; return $self unless @_; my $params = @_ > 1 ? {@_} : {%{$_[0]}}; $self->cost($params->{cost}) if $params->{cost}; $self->salt($params->{salt}) if $params->{salt}; $self->settings($params->{settings}) if $params->{settings}; $self->type($params->{type}) if $params->{type}; return $self; } sub reset { my $self = shift; $self->{_buffer} = ''; delete $self->{cost}; delete $self->{salt}; delete $self->{type}; return $self; } sub salt { my $self = shift; return $self->{salt} unless @_; my $salt = shift; # allow and undefined value to clear it unless (defined $salt) { delete $self->{salt}; return $self; } # all other values go through the check $self->_check_salt($salt); $self->{salt} = $salt; return $self; } sub settings { my $self = shift; unless (@_) { my $cost = sprintf('%02d', $self->{cost}); my $salt_base64 = encode_base64($self->salt, ""); $salt_base64 =~ tr{A-Za-z0-9+/=}{./A-Za-z0-9}d; my $type = defined($self->{type}) ? $self->{type} : '2a'; return "\$${type}\$${cost}\$${salt_base64}"; } my $settings = shift; Carp::croak "bad bcrypt settings" unless $settings =~ m#\A\$(2[abxy])\$([0-9]{2})\$ ([./A-Za-z0-9]{22})#x; my ($type, $cost, $salt_base64) = ($1, $2, $3); $self->type($type); $self->cost($cost); $self->salt(_de_base64($salt_base64)); return $self; } sub type { my $self = shift; return $self->{type} unless (@_); my $type = shift; Carp::croak "bad bcrypt type" unless $type =~ /^2[abxy]$/; $self->{type} = $type; return $self; } # Checks that the cost is a positive integerCroaks if it isn't sub _check_cost { my ($self, $cost) = @_; $cost = defined $cost ? $cost : $self->cost; if (!defined $cost || $cost !~ /^\d+$/) { Carp::croak "Cost must be a positive integer"; } } # Checks that the salt exactly 16 octets long. Croaks if it isn't sub _check_salt { my ($self, $salt) = @_; $salt = defined $salt ? $salt : $self->salt; unless ($salt && bytes::length($salt) == 16) { Carp::croak "Salt must be exactly 16 octets long"; } } sub _de_base64 { my ($text) = @_; $text =~ tr#./A-Za-z0-9#A-Za-z0-9+/#; return decode_base64($text); } 1; =encoding utf8 =head1 NAME Digest::Bcrypt - Perl interface to the bcrypt digest algorithm =head1 SYNOPSIS #!/usr/bin/env perl use strict; use warnings; use utf8; use Digest; # via the Digest module (recommended) my $bcrypt = Digest->new('Bcrypt', cost => 12, salt => 'abcdefgh♥stuff'); # You can forego the cost and salt in favor of settings strings: my $bcrypt = Digest->new('Bcrypt', settings => '$2a$20$GA.eY03tb02ea0DqbA.eG.'); # $cost is an integer between 5 and 31 $bcrypt->cost(12); # $type is a selection between 2a, 2b, 2x, and 2y $bcrypt->type('2b'); # $salt must be exactly 16 octets long $bcrypt->salt('abcdefgh♥stuff'); # OR, for good, random salts: use Data::Entropy::Algorithms qw(rand_bits); $bcrypt->salt(rand_bits(16*8)); # 16 octets # You can forego the cost and salt in favor of settings strings: $bcrypt->settings('$2a$20$GA.eY03tb02ea0DqbA.eG.'); # add some strings we want to make a secret of $bcrypt->add('some stuff', 'here and', 'here'); my $digest = $bcrypt->digest; $digest = $bcrypt->hexdigest; $digest = $bcrypt->b64digest; # bcrypt's own non-standard base64 dictionary $digest = $bcrypt->bcrypt_b64digest; # Now, let's create a password hash and check it later: use Data::Entropy::Algorithms qw(rand_bits); my $bcrypt = Digest->new('Bcrypt', type => '2b', cost => 20, salt => rand_bits(16*8)); my $settings = $bcrypt->settings(); # save for later checks. my $pass_hash = $bcrypt->add('Some secret password')->digest; # much later, we can check a password against our hash via: my $bcrypt = Digest->new('Bcrypt', settings => $settings); if ($bcrypt->add($value_from_user)->digest eq $known_pass_hash) { say "Your password matched"; } else { say "Try again!"; } # Now that you've seen how cumbersome/silly that is, # please use Crypt::Bcrypt instead of this module. =head1 NOTICE While maintenance for L will continue, there's no reason to use L when L already exists. We strongly suggest that you use L instead. This C interface is crufty and laborious to use when compared to that of L. =head1 DESCRIPTION L provides a L-based interface to the L library. Please note that you B set a C of exactly 16 octets in length, and you B provide a C in the range C<1..31>. =head1 ATTRIBUTES L implements the following attributes. =head2 cost $bcrypt = $bcrypt->cost(20); # allows for method chaining my $cost = $bcrypt->cost(); An integer in the range C<5..31>, this is required. See L for a detailed description of C in the context of the bcrypt algorithm. When called with no arguments, it will return the current cost. =head2 salt $bcrypt = $bcrypt->salt('abcdefgh♥stuff'); # allows for method chaining my $salt = $bcrypt->salt(); # OR, for good, random salts: use Data::Entropy::Algorithms qw(rand_bits); $bcrypt->salt(rand_bits(16*8)); # 16 octets Sets the value to be used as a salt. Bcrypt requires B 16 octets of salt. It is recommenced that you use a module like L to provide a truly randomized salt. When called with no arguments, it will return the current salt. =head2 settings $bcrypt = $bcrypt->settings('$2a$20$GA.eY03tb02ea0DqbA.eG.'); # allows for method chaining my $settings = $bcrypt->settings(); A C string can be used to set the L and L automatically. Setting the C will override any current values in your C and C attributes. For details on the C string requirements, please see L. When called with no arguments, it will return the current settings string. =head2 type $bcrypt = $bcrypt->type('2b'); # method chaining on mutations say $bcrypt->type(); # 2b This sets the subtype of bcrypt used. These subtypes are as defined in L. The available types are: C<2b> which is the current standard, C<2a> which is older; it's the one used in L, C<2y> which is considered equivalent to C<2b> and used in PHP. C<2x> which is very broken and only needed to work with ancient PHP versions. =head1 METHODS L inherits all methods from L and implements/overrides the following methods as well. =head2 new my $bcrypt = Digest->new('Bcrypt', %params); my $bcrypt = Digest::Bcrypt->new(%params); my $bcrypt = Digest->new('Bcrypt', \%params); my $bcrypt = Digest::Bcrypt->new(\%params); Creates a new C object. It is recommended that you use the L module in the first example rather than using L directly. Any of the L above can be passed in as a parameter. =head2 add $bcrypt->add("a"); $bcrypt->add("b"); $bcrypt->add("c"); $bcrypt->add("a")->add("b")->add("c"); $bcrypt->add("a", "b", "c"); $bcrypt->add("abc"); Adds data to the message we are calculating the digest for. All the above examples have the same effect. =head2 b64digest my $digest = $bcrypt->b64digest; Same as L, but will return the digest base64 encoded. The C of the returned string will be 31 and will only contain characters from the ranges C<'0'..'9'>, C<'A'..'Z'>, C<'a'..'z'>, C<'+'>, and C<'/'> The base64 encoded string returned is not padded to be a multiple of 4 bytes long. =head2 bcrypt_b64digest my $digest = $bcrypt->bcrypt_b64digest; Same as L, but will return the digest base64 encoded using the alphabet that is commonly used with bcrypt. The C of the returned string will be 31 and will only contain characters from the ranges C<'0'..'9'>, C<'A'..'Z'>, C<'a'..'z'>, C<'+'>, and C<'.'> The base64 encoded string returned is not padded to be a multiple of 4 bytes long. I This is bcrypt's own non-standard base64 alphabet, It is B compatible with the standard MIME base64 encoding. =head2 clone my $clone = $bcrypt->clone; Creates a clone of the C object, and returns it. =head2 digest my $digest = $bcrypt->digest; Returns the binary digest for the message. The returned string will be 23 bytes long. =head2 hexdigest my $digest = $bcrypt->hexdigest; Same as L, but will return the digest in hexadecimal form. The C of the returned string will be 46 and will only contain characters from the ranges C<'0'..'9'> and C<'a'..'f'>. =head2 reset $bcrypt->reset; Resets the object to the same internal state it was in when it was constructed. =head1 SEE ALSO L, L, L =head1 AUTHOR James Aitken C =head1 CONTRIBUTORS =over =item * Chase Whitener C =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2012 by James Aitken. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut author000755001750001750 014171076345 17230 5ustar00cwhitenercwhitener000000000000Digest-Bcrypt-1.212/xtrand_bits.t100755001750001750 234114171076345 21525 0ustar00cwhitenercwhitener000000000000Digest-Bcrypt-1.212/xt/authoruse strict; use warnings; use Data::Entropy::Algorithms qw(rand_bits); use Digest::Bcrypt; use Test::More; use Try::Tiny qw(try catch); my $ctx = try { return Digest::Bcrypt->new(); } catch { return "Couldn't create object: $!"; }; isa_ok($ctx, 'Digest::Bcrypt', 'new: got a proper object'); my $secret = "Super Secret Squirrel"; my $bits = rand_bits(128); is(length($bits), 16, 'rand_bits: 16 octets'); subtest "salt tests", sub { plan(skip_all => "Couldn't get a Digest::Bcrypt object") unless $ctx; my $res; my $err; $ctx->add($secret); try { $ctx->cost(5); $ctx->salt($bits); $res = $ctx->digest; } catch { $err = $_; }; is($err, undef, 'rand_bits salt: no error'); ok($res, 'rand_bits salt: got a proper digest'); $ctx->reset; }; subtest "bad salt tests", sub { plan(skip_all => "Couldn't get a Digest::Bcrypt object") unless $ctx; my $res; my $err; $ctx->add($secret); try { $ctx->cost(5); $ctx->salt(rand_bits(256)); $res = $ctx->digest; } catch { $err = $_; }; like($err, qr/Salt must/, 'bad salt: too many random bits'); is($res, undef, 'bad salt: no result'); }; done_testing(); 00-report-prereqs.t100755001750001750 1345214171076345 21322 0ustar00cwhitenercwhitener000000000000Digest-Bcrypt-1.212/t#!perl use strict; use warnings; # This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs 0.028 use Test::More tests => 1; use ExtUtils::MakeMaker; use File::Spec; # from $version::LAX my $lax_version_re = qr/(?: undef | (?: (?:[0-9]+) (?: \. | (?:\.[0-9]+) (?:_[0-9]+)? )? | (?:\.[0-9]+) (?:_[0-9]+)? ) | (?: v (?:[0-9]+) (?: (?:\.[0-9]+)+ (?:_[0-9]+)? )? | (?:[0-9]+)? (?:\.[0-9]+){2,} (?:_[0-9]+)? ) )/x; # hide optional CPAN::Meta modules from prereq scanner # and check if they are available my $cpan_meta = "CPAN::Meta"; my $cpan_meta_pre = "CPAN::Meta::Prereqs"; my $HAS_CPAN_META = eval "require $cpan_meta; $cpan_meta->VERSION('2.120900')" && eval "require $cpan_meta_pre"; ## no critic # Verify requirements? my $DO_VERIFY_PREREQS = 1; sub _max { my $max = shift; $max = ( $_ > $max ) ? $_ : $max for @_; return $max; } sub _merge_prereqs { my ($collector, $prereqs) = @_; # CPAN::Meta::Prereqs object if (ref $collector eq $cpan_meta_pre) { return $collector->with_merged_prereqs( CPAN::Meta::Prereqs->new( $prereqs ) ); } # Raw hashrefs for my $phase ( keys %$prereqs ) { for my $type ( keys %{ $prereqs->{$phase} } ) { for my $module ( keys %{ $prereqs->{$phase}{$type} } ) { $collector->{$phase}{$type}{$module} = $prereqs->{$phase}{$type}{$module}; } } } return $collector; } my @include = qw( ); my @exclude = qw( ); # Add static prereqs to the included modules list my $static_prereqs = do './t/00-report-prereqs.dd'; # Merge all prereqs (either with ::Prereqs or a hashref) my $full_prereqs = _merge_prereqs( ( $HAS_CPAN_META ? $cpan_meta_pre->new : {} ), $static_prereqs ); # Add dynamic prereqs to the included modules list (if we can) my ($source) = grep { -f } 'MYMETA.json', 'MYMETA.yml'; my $cpan_meta_error; if ( $source && $HAS_CPAN_META && (my $meta = eval { CPAN::Meta->load_file($source) } ) ) { $full_prereqs = _merge_prereqs($full_prereqs, $meta->prereqs); } else { $cpan_meta_error = $@; # capture error from CPAN::Meta->load_file($source) $source = 'static metadata'; } my @full_reports; my @dep_errors; my $req_hash = $HAS_CPAN_META ? $full_prereqs->as_string_hash : $full_prereqs; # Add static includes into a fake section for my $mod (@include) { $req_hash->{other}{modules}{$mod} = 0; } for my $phase ( qw(configure build test runtime develop other) ) { next unless $req_hash->{$phase}; next if ($phase eq 'develop' and not $ENV{AUTHOR_TESTING}); for my $type ( qw(requires recommends suggests conflicts modules) ) { next unless $req_hash->{$phase}{$type}; my $title = ucfirst($phase).' '.ucfirst($type); my @reports = [qw/Module Want Have/]; for my $mod ( sort keys %{ $req_hash->{$phase}{$type} } ) { next if $mod eq 'perl'; next if grep { $_ eq $mod } @exclude; my $file = $mod; $file =~ s{::}{/}g; $file .= ".pm"; my ($prefix) = grep { -e File::Spec->catfile($_, $file) } @INC; my $want = $req_hash->{$phase}{$type}{$mod}; $want = "undef" unless defined $want; $want = "any" if !$want && $want == 0; my $req_string = $want eq 'any' ? 'any version required' : "version '$want' required"; if ($prefix) { my $have = MM->parse_version( File::Spec->catfile($prefix, $file) ); $have = "undef" unless defined $have; push @reports, [$mod, $want, $have]; if ( $DO_VERIFY_PREREQS && $HAS_CPAN_META && $type eq 'requires' ) { if ( $have !~ /\A$lax_version_re\z/ ) { push @dep_errors, "$mod version '$have' cannot be parsed ($req_string)"; } elsif ( ! $full_prereqs->requirements_for( $phase, $type )->accepts_module( $mod => $have ) ) { push @dep_errors, "$mod version '$have' is not in required range '$want'"; } } } else { push @reports, [$mod, $want, "missing"]; if ( $DO_VERIFY_PREREQS && $type eq 'requires' ) { push @dep_errors, "$mod is not installed ($req_string)"; } } } if ( @reports ) { push @full_reports, "=== $title ===\n\n"; my $ml = _max( map { length $_->[0] } @reports ); my $wl = _max( map { length $_->[1] } @reports ); my $hl = _max( map { length $_->[2] } @reports ); if ($type eq 'modules') { splice @reports, 1, 0, ["-" x $ml, "", "-" x $hl]; push @full_reports, map { sprintf(" %*s %*s\n", -$ml, $_->[0], $hl, $_->[2]) } @reports; } else { splice @reports, 1, 0, ["-" x $ml, "-" x $wl, "-" x $hl]; push @full_reports, map { sprintf(" %*s %*s %*s\n", -$ml, $_->[0], $wl, $_->[1], $hl, $_->[2]) } @reports; } push @full_reports, "\n"; } } } if ( @full_reports ) { diag "\nVersions for all modules listed in $source (including optional ones):\n\n", @full_reports; } if ( $cpan_meta_error || @dep_errors ) { diag "\n*** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***\n"; } if ( $cpan_meta_error ) { my ($orig_source) = grep { -f } 'MYMETA.json', 'MYMETA.yml'; diag "\nCPAN::Meta->load_file('$orig_source') failed with: $cpan_meta_error\n"; } if ( @dep_errors ) { diag join("\n", "\nThe following REQUIRED prerequisites were not satisfied:\n", @dep_errors, "\n" ); } pass('Reported prereqs'); # vim: ts=4 sts=4 sw=4 et: release000755001750001750 014171076345 17346 5ustar00cwhitenercwhitener000000000000Digest-Bcrypt-1.212/xtkwalitee.t100755001750001750 27514171076345 21467 0ustar00cwhitenercwhitener000000000000Digest-Bcrypt-1.212/xt/release# this test was generated with Dist::Zilla::Plugin::Test::Kwalitee 2.12 use strict; use warnings; use Test::More 0.88; use Test::Kwalitee 1.21 'kwalitee_ok'; kwalitee_ok(); done_testing; pod-spell.t100755001750001750 53014171076345 21435 0ustar00cwhitenercwhitener000000000000Digest-Bcrypt-1.212/xt/authoruse strict; use warnings; use Test::More; # generated by Dist::Zilla::Plugin::Test::PodSpelling 2.007005 use Test::Spelling 0.12; use Pod::Wordlist; set_spell_cmd('aspell list'); add_stopwords(); all_pod_files_spelling_ok( qw( bin lib ) ); __DATA__ Aitken Bcrypt Chase Digest James Whitener capoeirab hexdigest jaitken lib loonypandora 003_create_digests.t100755001750001750 1502214171076345 21455 0ustar00cwhitenercwhitener000000000000Digest-Bcrypt-1.212/tuse strict; use warnings; use Digest; use Digest::Bcrypt; use Test::More; use Try::Tiny qw( try catch ); my $secret = "Super Secret Squirrel"; my $salt = " known salt "; my $cost = 5; # Object is reset after each hash is generated my $direct = Digest::Bcrypt->new; isa_ok($direct, 'Digest::Bcrypt', 'new: direct dist use syntax'); my $indirect = Digest->new('Bcrypt'); isa_ok($direct, 'Digest::Bcrypt', 'new: indirect dist use via Digest'); # direct binary { my $res = try { $direct->add($secret); is($direct->{_buffer}, $secret, 'direct binary: buffer set correctly'); $direct->salt($salt); is($direct->salt(), $salt, 'direct binary: salt set correctly'); $direct->cost($cost); is($direct->cost(), '05', 'direct binary: cost set correctly'); ok($direct->digest, "Creates Binary Digest"); return ''; } catch { return "Error: $_" }; is($res, '', 'direct binary: no errors trapped'); is($direct->{_buffer}, '', 'direct binary: buffer emptied after'); is($direct->salt(), undef, 'direct binary: salt emptied after'); is($direct->cost(), undef, 'direct binary: cost empted after'); } # direct hex { my $res = try { $direct->add($secret); is($direct->{_buffer}, $secret, 'direct hex: buffer set correctly'); $direct->salt($salt); is($direct->salt(), $salt, 'direct hex: salt set correctly'); $direct->cost($cost); is($direct->cost(), '05', 'direct hex: cost set correctly'); return $direct->hexdigest; } catch { return "Error: $_" }; is( $res, '611d856adaf4357f2891de1e1024d9fa0e49b67ffc724d', "direct hex: proper value" ); is($direct->{_buffer}, '', 'direct hex: buffer emptied after'); is($direct->salt(), undef, 'direct hex: salt emptied after'); is($direct->cost(), undef, 'direct hex: cost empted after'); } # direct b64 { my $res = try { $direct->add($secret); is($direct->{_buffer}, $secret, 'direct b64: buffer set correctly'); $direct->salt($salt); is($direct->salt(), $salt, 'direct b64: salt set correctly'); $direct->cost($cost); is($direct->cost(), '05', 'direct b64: cost set correctly'); return $direct->b64digest; } catch { return "Error: $_" }; is($res, 'YR2Fatr0NX8okd4eECTZ+g5Jtn/8ck0', "direct b64: proper value"); is($direct->{_buffer}, '', 'direct b64: buffer emptied after'); is($direct->salt(), undef, 'direct b64: salt emptied after'); is($direct->cost(), undef, 'direct b64: cost empted after'); } # direct bcrypt_b64 { my $res = try { $direct->add($secret); is($direct->{_buffer}, $secret, 'direct bcrypt_b64: buffer set correctly'); $direct->salt($salt); is($direct->salt(), $salt, 'direct bcrypt_b64: salt set correctly'); $direct->cost($cost); is($direct->cost(), '05', 'direct bcrypt_b64: cost set correctly'); return $direct->bcrypt_b64digest; } catch { return "Error: $_" }; is( $res, 'WP0DYrpyLV6mib2cCARX8e3Hrl96aiy', "direct bcrypt_b64: proper value" ); is($direct->{_buffer}, '', 'direct bcrypt_b64: buffer emptied after'); is($direct->salt(), undef, 'direct bcrypt_b64: salt emptied after'); is($direct->cost(), undef, 'direct bcrypt_b64: cost empted after'); } # indirect binary { my $res = try { $indirect->add($secret); is($indirect->{_buffer}, $secret, 'indirect binary: buffer set correctly'); $indirect->salt($salt); is($indirect->salt(), $salt, 'indirect binary: salt set correctly'); $indirect->cost($cost); is($indirect->cost(), '05', 'indirect binary: cost set correctly'); ok($indirect->digest, "indirect binary: digest created"); return ''; } catch { return "Error: $_" }; is($res, '', 'indirect binary: no errors trapped'); is($indirect->{_buffer}, '', 'indirect binary: buffer emptied after'); is($indirect->salt(), undef, 'indirect binary: salt emptied after'); is($indirect->cost(), undef, 'indirect binary: cost empted after'); } # indirect hex { my $res = try { $indirect->add($secret); is($indirect->{_buffer}, $secret, 'indirect hex: buffer set correctly'); $indirect->salt($salt); is($indirect->salt(), $salt, 'indirect hex: salt set correctly'); $indirect->cost($cost); is($indirect->cost(), '05', 'indirect hex: cost set correctly'); return $indirect->hexdigest; } catch { return "Error: $_" }; is( $res, '611d856adaf4357f2891de1e1024d9fa0e49b67ffc724d', "indirect hex: proper value" ); is($indirect->{_buffer}, '', 'indirect hex: buffer emptied after'); is($indirect->salt(), undef, 'indirect hex: salt emptied after'); is($indirect->cost(), undef, 'indirect hex: cost empted after'); } # indirect b64 { my $res = try { $indirect->add($secret); is($indirect->{_buffer}, $secret, 'indirect b64: buffer set correctly'); $indirect->salt($salt); is($indirect->salt(), $salt, 'indirect b64: salt set correctly'); $indirect->cost($cost); is($indirect->cost(), '05', 'indirect b64: cost set correctly'); return $indirect->b64digest; } catch { return "Error: $_" }; is($res, 'YR2Fatr0NX8okd4eECTZ+g5Jtn/8ck0', "indirect b64: proper value"); is($indirect->{_buffer}, '', 'indirect b64: buffer emptied after'); is($indirect->salt(), undef, 'indirect b64: salt emptied after'); is($indirect->cost(), undef, 'indirect b64: cost empted after'); } # indirect bcrypt_b64 { my $res = try { $indirect->add($secret); is($indirect->{_buffer}, $secret, 'indirect bcrypt_b64: buffer set correctly'); $indirect->salt($salt); is($indirect->salt(), $salt, 'indirect bcrypt_b64: salt set correctly'); $indirect->cost($cost); is($indirect->cost(), '05', 'indirect bcrypt_b64: cost set correctly'); return $indirect->bcrypt_b64digest; } catch { return "Error: $_" }; is( $res, 'WP0DYrpyLV6mib2cCARX8e3Hrl96aiy', "indirect bcrypt_b64: proper value" ); is($indirect->{_buffer}, '', 'indirect bcrypt_b64: buffer emptied after'); is($indirect->salt(), undef, 'indirect bcrypt_b64: salt emptied after'); is($indirect->cost(), undef, 'indirect bcrypt_b64: cost empted after'); } done_testing(); 004_error_handling.t100755001750001750 661614171076345 21457 0ustar00cwhitenercwhitener000000000000Digest-Bcrypt-1.212/tuse strict; use warnings; use Digest::Bcrypt (); use Try::Tiny qw(try catch); use Test::More; my $secret = "Super Secret Squirrel"; my $salt = " known salt "; my $ctx = Digest::Bcrypt->new(); isa_ok($ctx, 'Digest::Bcrypt', 'new: got a proper object'); { my $res = undef; my $err = undef; try { $ctx->reset(); $ctx->add($secret); $ctx->settings('$2a$20$GA.eY'); $res = $ctx->digest; } catch { $err = $_; }; like $err, qr/bad bcrypt settings/, 'settings: dies on invalid setup'; is $res, undef, 'no digest'; $res = undef; $err = undef; try { $ctx->reset; $ctx->add($secret); $ctx->settings('$2a$-1$GA.eY03tb02ea0DqbA.eG.'); $res = $ctx->digest; } catch { $err = $_; }; like $err, qr/bad bcrypt/i, 'settings: dies with bad cost'; is $res, undef, 'no digest'; $res = undef; $err = undef; try { $ctx->reset; $ctx->add($secret); $ctx->settings('$2a$20$GA.eY03tb02eZFOeGA.'); $res = $ctx->digest; } catch { $err = $_; }; like $err, qr/bad bcrypt settings/i, 'settings: dies with bad salt part'; is $res, undef, 'no digest'; } { my $res = undef; my $err = undef; try { $ctx->reset; $ctx->add($secret); $ctx->cost('foobar'); $res = $ctx->digest; } catch { $err = $_; }; like $err, qr/Cost must/i, 'cost: dies on non-numeric'; is $res, undef, 'no digest'; $res = undef; $err = undef; try { $ctx->reset; $ctx->add($secret); $ctx->salt($salt); $ctx->cost(32); $res = $ctx->digest; } catch { $err = $_; }; like $err, qr/Invalid cost/i, 'cost: dies when greater than 31'; is $res, undef, 'no digest'; $res = undef; $err = undef; try { $ctx->reset; $ctx->add($secret); $ctx->salt($salt); $ctx->cost(0); $res = $ctx->digest; } catch { $err = $_; }; like $err, qr/Invalid cost/i, 'cost: dies when too low'; is $res, undef, 'no digest'; $res = undef; $err = undef; try { $ctx->reset; $ctx->add($secret); $res = $ctx->digest; } catch { $err = $_; }; like $err, qr/Cost must/i, 'cost: dies when none specified'; is $res, undef, 'no digest'; } { my $res = undef; my $err = undef; try { $ctx->reset; $ctx->add($secret); $ctx->cost(5); $ctx->salt('too small'); $res = $ctx->digest; } catch { $err = $_; }; like $err, qr/Salt must/i, 'salt: dies on too small of a salt'; is $res, undef, 'no digest'; $res = undef; $err = undef; try { $ctx->reset; $ctx->add($secret); $ctx->cost(5); $ctx->salt(); $res = $ctx->digest; } catch { $err = $_; }; like $err, qr/Salt must/i, 'salt: dies without salt'; is $res, undef, 'no digest'; $res = undef; $err = undef; try { $ctx->reset; $ctx->add($secret); $ctx->cost(5); $ctx->salt('This is a mighty big salt cannon we have here!'); $res = $ctx->digest; } catch { $err = $_; }; like $err, qr/Salt must/i, 'salt: dies when salt too large'; is $res, undef, 'no digest'; } done_testing(); pod-syntax.t100755001750001750 25214171076345 21645 0ustar00cwhitenercwhitener000000000000Digest-Bcrypt-1.212/xt/author#!perl # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use strict; use warnings; use Test::More; use Test::Pod 1.41; all_pod_files_ok(); 00-report-prereqs.dd100755001750001750 472714171076345 21433 0ustar00cwhitenercwhitener000000000000Digest-Bcrypt-1.212/tdo { my $x = { 'configure' => { 'requires' => { 'ExtUtils::MakeMaker' => '0' } }, 'develop' => { 'requires' => { 'Data::Entropy::Algorithms' => '0', 'File::Spec' => '0', 'IO::Handle' => '0', 'IPC::Open3' => '0', 'Pod::Coverage::TrustPod' => '0', 'Test::CPAN::Changes' => '0.4', 'Test::CheckManifest' => '1.29', 'Test::Kwalitee' => '1.22', 'Test::More' => '0.88', 'Test::Pod' => '1.41', 'Test::Pod::Coverage' => '1.08', 'Test::Pod::Spelling::CommonMistakes' => '1.000', 'Test::Spelling' => '0.12', 'Test::Version' => '1' } }, 'runtime' => { 'requires' => { 'Carp' => '0', 'Crypt::Bcrypt' => '0', 'Digest' => '0', 'MIME::Base64' => '0', 'bytes' => '0', 'parent' => '0', 'perl' => '5.008001', 'strict' => '0', 'utf8' => '0', 'warnings' => '0' } }, 'test' => { 'recommends' => { 'CPAN::Meta' => '2.120900' }, 'requires' => { 'ExtUtils::MakeMaker' => '0', 'File::Spec' => '0', 'Scalar::Util' => '0.88', 'Test::More' => '0.88', 'Try::Tiny' => '0.24' } } }; $x; }00-compile.t100755001750001750 254514171076345 21433 0ustar00cwhitenercwhitener000000000000Digest-Bcrypt-1.212/xt/authoruse 5.006; use strict; use warnings; # this test was generated with Dist::Zilla::Plugin::Test::Compile 2.058 use Test::More; plan tests => 2; my @module_files = ( 'Digest/Bcrypt.pm' ); # no fake home requested my @switches = ( -d 'blib' ? '-Mblib' : '-Ilib', ); use File::Spec; use IPC::Open3; use IO::Handle; open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!"; my @warnings; for my $lib (@module_files) { # see L my $stderr = IO::Handle->new; diag('Running: ', join(', ', map { my $str = $_; $str =~ s/'/\\'/g; q{'} . $str . q{'} } $^X, @switches, '-e', "require q[$lib]")) if $ENV{PERL_COMPILE_TEST_DEBUG}; my $pid = open3($stdin, '>&STDERR', $stderr, $^X, @switches, '-e', "require q[$lib]"); binmode $stderr, ':crlf' if $^O eq 'MSWin32'; my @_warnings = <$stderr>; waitpid($pid, 0); is($?, 0, "$lib loaded ok"); shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/ and not eval { +require blib; blib->VERSION('1.01') }; if (@_warnings) { warn @_warnings; push @warnings, @_warnings; } } is(scalar(@warnings), 0, 'no warnings found') or diag 'got warnings: ', ( Test::More->can('explain') ? Test::More::explain(\@warnings) : join("\n", '', @warnings) ); test-version.t100755001750001750 63714171076345 22210 0ustar00cwhitenercwhitener000000000000Digest-Bcrypt-1.212/xt/authoruse strict; use warnings; use Test::More; # generated by Dist::Zilla::Plugin::Test::Version 1.09 use Test::Version; my @imports = qw( version_all_ok ); my $params = { is_strict => 0, has_version => 1, multiple => 0, }; push @imports, $params if version->parse( $Test::Version::VERSION ) >= version->parse('1.002'); Test::Version->import(@imports); version_all_ok; done_testing; pod-coverage.t100755001750001750 172014171076345 22133 0ustar00cwhitenercwhitener000000000000Digest-Bcrypt-1.212/xt/author#!perl # This file was automatically generated by Dist::Zilla::Plugin::Test::Pod::Coverage::Configurable 0.07. use Test::Pod::Coverage 1.08; use Test::More 0.88; BEGIN { if ( $] <= 5.008008 ) { plan skip_all => 'These tests require Pod::Coverage::TrustPod, which only works with Perl 5.8.9+'; } } use Pod::Coverage::TrustPod; my %skip = map { $_ => 1 } qw( ); my @modules; for my $module ( all_modules() ) { next if $skip{$module}; push @modules, $module; } plan skip_all => 'All the modules we found were excluded from POD coverage test.' unless @modules; plan tests => scalar @modules; my %trustme = (); my @also_private; for my $module ( sort @modules ) { pod_coverage_ok( $module, { coverage_class => 'Pod::Coverage::TrustPod', also_private => \@also_private, trustme => $trustme{$module} || [], }, "pod coverage for $module" ); } done_testing(); changes_has_content.t100755001750001750 210114171076345 23665 0ustar00cwhitenercwhitener000000000000Digest-Bcrypt-1.212/xt/releaseuse Test::More tests => 2; note 'Checking Changes'; my $changes_file = 'Changes'; my $newver = '1.212'; my $trial_token = '-TRIAL'; my $encoding = 'UTF-8'; SKIP: { ok(-e $changes_file, "$changes_file file exists") or skip 'Changes is missing', 1; ok(_get_changes($newver), "$changes_file has content for $newver"); } done_testing; sub _get_changes { my $newver = shift; # parse changelog to find commit message open(my $fh, '<', $changes_file) or die "cannot open $changes_file: $!"; my $changelog = join('', <$fh>); if ($encoding) { require Encode; $changelog = Encode::decode($encoding, $changelog, Encode::FB_CROAK()); } close $fh; my @content = grep { /^$newver(?:$trial_token)?(?:\s+|$)/ ... /^\S/ } # from newver to un-indented split /\n/, $changelog; shift @content; # drop the version line # drop unindented last line and trailing blank lines pop @content while ( @content && $content[-1] =~ /^(?:\S|\s*$)/ ); # return number of non-blank lines return scalar @content; }