Merge branch 'justus/pyme3'
This commit is contained in:
commit
db34332535
26
configure.ac
26
configure.ac
@ -160,8 +160,8 @@ have_w32_system=no
|
||||
have_w64_system=no
|
||||
build_w32_glib=no
|
||||
build_w32_qt=no
|
||||
available_languages="cpp cl qt"
|
||||
default_languages="cpp cl qt"
|
||||
available_languages="cl cpp python qt"
|
||||
default_languages="cl cpp python qt"
|
||||
case "${host}" in
|
||||
x86_64-*mingw32*)
|
||||
have_w64_system=yes
|
||||
@ -339,6 +339,26 @@ fi
|
||||
AM_CONDITIONAL([HAVE_DOXYGEN],
|
||||
[test -n "$DOXYGEN"])
|
||||
|
||||
# Python bindings.
|
||||
LIST_MEMBER("python", $enabled_languages)
|
||||
if test "$found" = "1"; then
|
||||
AX_PKG_SWIG
|
||||
if test -z "$SWIG"; then
|
||||
if test "$explicit_languages" = "1"; then
|
||||
die=yes
|
||||
AC_MSG_NOTICE([[
|
||||
***
|
||||
*** You need SWIG to build the Python bindings.
|
||||
***]])
|
||||
else
|
||||
enabled_languages=$(echo $enabled_languages | sed 's/qt//')
|
||||
fi
|
||||
else
|
||||
AM_PATH_PYTHON([3.2])
|
||||
AX_SWIG_PYTHON
|
||||
fi
|
||||
fi
|
||||
|
||||
AC_SUBST(ENABLED_LANGUAGES, $enabled_languages)
|
||||
|
||||
#
|
||||
@ -682,7 +702,6 @@ AC_SUBST(emacs_local_vars_begin, [['Local][ ][Variables:']])
|
||||
AC_SUBST(emacs_local_vars_read_only, ['buffer-read-only: t'])
|
||||
AC_SUBST(emacs_local_vars_end, ['End:'])
|
||||
|
||||
|
||||
# Last check.
|
||||
die=no
|
||||
if test "$have_gpg_error" = "no"; then
|
||||
@ -737,6 +756,7 @@ AC_CONFIG_FILES(lang/qt/tests/Makefile)
|
||||
AC_CONFIG_FILES([lang/Makefile lang/cl/Makefile lang/cl/gpgme.asd])
|
||||
AM_COND_IF([HAVE_DOXYGEN], [AC_CONFIG_FILES([lang/qt/doc/Doxyfile])])
|
||||
AC_CONFIG_FILES(lang/qt/doc/Makefile)
|
||||
AC_CONFIG_FILES([lang/python/Makefile lang/python/tests/Makefile])
|
||||
AC_OUTPUT
|
||||
|
||||
echo "
|
||||
|
@ -10,5 +10,6 @@ sub-directory.
|
||||
Directory Language
|
||||
|
||||
cl Common Lisp
|
||||
cpp C++
|
||||
qt Qt-Framework API
|
||||
cpp C++
|
||||
qt Qt-Framework API
|
||||
python Python 3 (port of PyME 0.9.0)
|
||||
|
340
lang/python/COPYING
Normal file
340
lang/python/COPYING
Normal file
@ -0,0 +1,340 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU 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. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Library General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), 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 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 show them these terms so they know 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.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
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 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 derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
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 License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
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.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary 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
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 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 Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing 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 for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
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.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. 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 this 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
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. 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
|
||||
|
||||
11. 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.
|
||||
|
||||
12. 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
|
||||
|
||||
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 the public, 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.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
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 2 of the License, 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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) year 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 is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Library General
|
||||
Public License instead of this License.
|
508
lang/python/COPYING.LESSER
Normal file
508
lang/python/COPYING.LESSER
Normal file
@ -0,0 +1,508 @@
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
|
||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the Lesser GPL. It also counts
|
||||
as the successor of the GNU Library Public License, version 2, hence
|
||||
the version number 2.1.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Lesser General Public License, applies to some
|
||||
specially designated software packages--typically libraries--of the
|
||||
Free Software Foundation and other authors who decide to use it. You
|
||||
can use it too, but we suggest you first think carefully about whether
|
||||
this license or the ordinary General Public License is the better
|
||||
strategy to use in any particular case, based on the explanations
|
||||
below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use,
|
||||
not price. Our General Public Licenses are designed to make sure that
|
||||
you have the freedom to distribute copies of free software (and charge
|
||||
for this service if you wish); that you receive source code or can get
|
||||
it if you want it; that you can change the software and use pieces of
|
||||
it in new free programs; and that you are informed that you can do
|
||||
these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
distributors to deny you these rights or to ask you to surrender these
|
||||
rights. These restrictions translate to certain responsibilities for
|
||||
you if you distribute copies of the library or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link other code with the library, you must provide
|
||||
complete object files to the recipients, so that they can relink them
|
||||
with the library after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the
|
||||
library, and (2) we offer you this license, which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that
|
||||
there is no warranty for the free library. Also, if the library is
|
||||
modified by someone else and passed on, the recipients should know
|
||||
that what they have is not the original version, so that the original
|
||||
author's reputation will not be affected by problems that might be
|
||||
introduced by others.
|
||||
|
||||
Finally, software patents pose a constant threat to the existence of
|
||||
any free program. We wish to make sure that a company cannot
|
||||
effectively restrict the users of a free program by obtaining a
|
||||
restrictive license from a patent holder. Therefore, we insist that
|
||||
any patent license obtained for a version of the library must be
|
||||
consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the
|
||||
ordinary GNU General Public License. This license, the GNU Lesser
|
||||
General Public License, applies to certain designated libraries, and
|
||||
is quite different from the ordinary General Public License. We use
|
||||
this license for certain libraries in order to permit linking those
|
||||
libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using
|
||||
a shared library, the combination of the two is legally speaking a
|
||||
combined work, a derivative of the original library. The ordinary
|
||||
General Public License therefore permits such linking only if the
|
||||
entire combination fits its criteria of freedom. The Lesser General
|
||||
Public License permits more lax criteria for linking other code with
|
||||
the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it
|
||||
does Less to protect the user's freedom than the ordinary General
|
||||
Public License. It also provides other free software developers Less
|
||||
of an advantage over competing non-free programs. These disadvantages
|
||||
are the reason we use the ordinary General Public License for many
|
||||
libraries. However, the Lesser license provides advantages in certain
|
||||
special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to
|
||||
encourage the widest possible use of a certain library, so that it
|
||||
becomes a de-facto standard. To achieve this, non-free programs must
|
||||
be allowed to use the library. A more frequent case is that a free
|
||||
library does the same job as widely used non-free libraries. In this
|
||||
case, there is little to gain by limiting the free library to free
|
||||
software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free
|
||||
programs enables a greater number of people to use a large body of
|
||||
free software. For example, permission to use the GNU C Library in
|
||||
non-free programs enables many more people to use the whole GNU
|
||||
operating system, as well as its variant, the GNU/Linux operating
|
||||
system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the
|
||||
users' freedom, it does ensure that the user of a program that is
|
||||
linked with the Library has the freedom and the wherewithal to run
|
||||
that program using a modified version of the Library.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, whereas the latter must
|
||||
be combined with the library in order to run.
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser General Public License (also called "this License").
|
||||
Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control
|
||||
compilation and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete 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 License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
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.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also combine or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) Accompany the work with a written offer, valid for at least
|
||||
three years, to give the same user the materials specified in
|
||||
Subsection 6a, above, for a charge no more than the cost of
|
||||
performing this distribution.
|
||||
|
||||
d) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
e) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the materials to be distributed need not include anything that is
|
||||
normally distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties with
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply, and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License
|
||||
may add an explicit geographical distribution limitation excluding those
|
||||
countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Lesser 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 Library
|
||||
specifies a version number of this 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 Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
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
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "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
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. 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 LIBRARY 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
|
||||
LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Libraries
|
||||
|
||||
If you develop a new library, and you want it to be of the greatest
|
||||
possible use to the public, we recommend making it free software that
|
||||
everyone can redistribute and change. You can do so by permitting
|
||||
redistribution under these terms (or, alternatively, under the terms
|
||||
of the ordinary General Public License).
|
||||
|
||||
To apply these terms, attach the following notices to the library.
|
||||
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.
|
||||
|
||||
|
||||
<one line to give the library's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or
|
||||
your school, if any, to sign a "copyright disclaimer" for the library,
|
||||
if necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||
library `Frob' (a library for tweaking knobs) written by James
|
||||
Random Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1990
|
||||
Ty Coon, President of Vice
|
||||
|
||||
That's all there is to it!
|
15
lang/python/INSTALL
Normal file
15
lang/python/INSTALL
Normal file
@ -0,0 +1,15 @@
|
||||
To build pyme module without installing it run 'make'.
|
||||
|
||||
To install pyme module run 'make install'. The module will be installed in the
|
||||
site-packages subdirectory of the python library directory.
|
||||
|
||||
To delete all files generated during build run 'make reallyclean'
|
||||
|
||||
To build documentation run 'make docs'. HTML files will be generated in 'doc'
|
||||
subdirectory.
|
||||
|
||||
To build distribution files including Debian packages run 'make dist'
|
||||
To build distribution archive without Debian packages and without debian
|
||||
subdirectory run 'make nondeb-dist'
|
||||
Note, Debian packages and distribution archive will be generated in the parent
|
||||
directory.
|
5
lang/python/MANIFEST.in
Normal file
5
lang/python/MANIFEST.in
Normal file
@ -0,0 +1,5 @@
|
||||
recursive-include examples *.py *.glade *.gladep
|
||||
include gpgme-h-clean.py gpgme.i
|
||||
include helpers.c helpers.h
|
||||
include Makefile
|
||||
recursive-include pyme *.py
|
54
lang/python/Makefile.am
Normal file
54
lang/python/Makefile.am
Normal file
@ -0,0 +1,54 @@
|
||||
# Makefile.am for the Python bindings.
|
||||
# Copyright (C) 2016 g10 Code GmbH
|
||||
#
|
||||
# This file is part of GPGME.
|
||||
#
|
||||
# GPGME 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 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# GPGME 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 Lesser General
|
||||
# Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
EXTRA_DIST = README.rst
|
||||
SUBDIRS = tests
|
||||
|
||||
# Cleanup gpgme.h from deprecated functions and typedefs.
|
||||
gpgme.h: ../../src/gpgme.h
|
||||
$(PYTHON) $(srcdir)/gpgme-h-clean.py $< >$@
|
||||
|
||||
# For VPATH builds we need to copy some files because Python's
|
||||
# distutils are not VPATH-aware.
|
||||
copystamp: $(srcdir)/pyme $(srcdir)/helpers.c $(srcdir)/helpers.h
|
||||
if test "$(srcdir)" != "$(builddir)" ; then cp -a $^ . ; fi
|
||||
touch $@
|
||||
|
||||
gpgme_wrap.c pyme/pygpgme.py: gpgme.i gpgme.h copystamp
|
||||
$(SWIG) -python -py3 $(SWIGOPT) \
|
||||
-o $(builddir)/gpgme_wrap.c -outdir $(builddir)/pyme \
|
||||
$<
|
||||
|
||||
all-local: gpgme_wrap.c pyme/pygpgme.py copystamp
|
||||
$(PYTHON) $(srcdir)/setup.py build --verbose
|
||||
|
||||
clean-local:
|
||||
rm -rf -- build gpgme.h gpgme_wrap.c pyme/pygpgme.py copystamp
|
||||
if test "$(srcdir)" != "$(builddir)" ; then \
|
||||
rm -rf pyme helpers.c helpers.h ; \
|
||||
fi
|
||||
|
||||
install-exec-local:
|
||||
$(PYTHON) $(srcdir)/setup.py install \
|
||||
--prefix $(DESTDIR)$(prefix) \
|
||||
--record $(DESTDIR)$(pythondir)/pyme/install_files.txt \
|
||||
--verbose
|
||||
|
||||
uninstall-local:
|
||||
xargs <$(DESTDIR)$(pythondir)/pyme/install_files.txt -- rm -rf --
|
||||
rm -rf -- $(DESTDIR)$(pythondir)/pyme
|
48
lang/python/README.rst
Normal file
48
lang/python/README.rst
Normal file
@ -0,0 +1,48 @@
|
||||
====
|
||||
PyME
|
||||
====
|
||||
|
||||
PyMe is a python interface to the `GPGME
|
||||
<https://www.gnupg.org/related_software/gpgme/>`_ library.
|
||||
|
||||
PyMe's development model is a `GPGME
|
||||
<https://www.gnupg.org/related_software/gpgme/>`_ + Python 3 + `SWIG
|
||||
<http://www.swig.org/>`_ combination which means that most of the functions and
|
||||
types are converted from C into Python 3 automatically by SWIG. In short, to be
|
||||
able to use PyMe you need to be `familiar with GPGME
|
||||
<https://www.gnupg.org/documentation/manuals/gpgme/>`_.
|
||||
|
||||
|
||||
-------
|
||||
Authors
|
||||
-------
|
||||
|
||||
* John Goerzen, `Complete.Org <http://www.complete.org/JohnGoerzen>`_, 2002.
|
||||
* Igor Belyi, `PyME 0.8 <http://pyme.sourceforge.net/>`_, 2004-2008.
|
||||
* Martin Albrecht, `PyME 0.9+ <https://bitbucket.org/malb/pyme>`_, 2014 to present.
|
||||
* Ben McGinnes, `PyME Python 3 Port <https://git.gnupg.org/gpgme.git/lang/py3-pyme>`_, 2015 to present.
|
||||
|
||||
|
||||
------------
|
||||
Mailing List
|
||||
------------
|
||||
|
||||
PyME's support and development `mailing list
|
||||
<http://sourceforge.net/p/pyme/mailman/pyme-help/>`_ is hosted by sourceforge.
|
||||
|
||||
|
||||
-------
|
||||
History
|
||||
-------
|
||||
|
||||
* The latest version of PyME for Python 3.2 and above (as of May, 2015) is v0.9.1.
|
||||
https://git.gnupg.org/gpgme.git/lang/py3-pyme
|
||||
|
||||
* The latest version of PyME for Python 2.6 and 2.7 (as of this writing) is v0.9.0.
|
||||
https://bitbucket.org/malb/pyme
|
||||
|
||||
* A previous version of PyME v0.8.0 can be found on sourceforge:
|
||||
http://pyme.sourceforge.net/
|
||||
|
||||
* A previous version of PyME v0.5.1 which works with GPGME v0.3.15 can be found
|
||||
on John Goerzen's PyMe page: http://quux.org/devel/pyme/
|
55
lang/python/docs/Short_History.rst
Normal file
55
lang/python/docs/Short_History.rst
Normal file
@ -0,0 +1,55 @@
|
||||
=======================
|
||||
A Short History of PyME
|
||||
=======================
|
||||
|
||||
In 2002 John Goerzen released PyME; Python bindings for the GPGME
|
||||
module which utilised the current release of Python of the time
|
||||
(Python 2.2 or 2.3) and SWIG. Shortly after creating it and ensuring
|
||||
it worked he stopped supporting it, though left his work available on
|
||||
his Gopher site.
|
||||
|
||||
A couple of years later the project was picked up by Igor Belyi and
|
||||
actively developed and maintained by him from 2004 to 2008. Igor's
|
||||
whereabouts at the time of this document's creation are unknown, but
|
||||
the current authors do hope he is well. We're assuming (or hoping)
|
||||
that life did what life does and made continuing untenable.
|
||||
|
||||
In 2014 Martin Albrecht wanted to patch a bug in the PyME code and
|
||||
discovered the absence of Igor. Following a discussion on the PyME
|
||||
mailing list he became the new maintainer for PyME, releasing version
|
||||
0.9.0 in May of that year. He remains the maintainer of the original
|
||||
PyME release in Python 2.6 and 2.7 (available via PyPI).
|
||||
|
||||
In 2015 Ben McGinnes approached Martin about a Python 3 version, while
|
||||
investigating how complex a task this would be the task ended up being
|
||||
completed. A subsequent discussion with Werner Koch led to the
|
||||
decision to fold the Python 3 port back into the original GPGME
|
||||
release in the languages subdirectory for non-C bindings. Ben is the
|
||||
maintainer of the Python 3 port within GPGME.
|
||||
|
||||
|
||||
---------------------
|
||||
The Annoyances of Git
|
||||
---------------------
|
||||
|
||||
As anyone who has ever worked with git knows, submodules are horrible
|
||||
way to deal with pretty much anything. In the interests of avoiding
|
||||
migraines, that is being skipped with addition of PyME to GPGME.
|
||||
Instead the files will be added to the subdirectory, along with a copy
|
||||
of the entire git log up to that point as a separate file within the
|
||||
docs directory (old-commits.log). As the log for PyME is nearly 100KB
|
||||
and the log for GPGME is approximately 1MB, this would cause
|
||||
considerable bloat, as well as some confusion, should the two be
|
||||
merged. Hence the unfortunate, but necessary, step to simply move the
|
||||
files. A regular repository version will be maintained should it be
|
||||
possible to implement this better in the future.
|
||||
|
||||
|
||||
------------------
|
||||
The Perils of PyPI
|
||||
------------------
|
||||
|
||||
At the current time the Python 3 fork is not available via PyPI and
|
||||
the pip installer. The recommended installation method is to follow
|
||||
the instructions in lang/py3-pyme/INSTALL. This will build the
|
||||
necessary SWIG portions against the installed version of GPGME.
|
23
lang/python/docs/TODO.rst
Normal file
23
lang/python/docs/TODO.rst
Normal file
@ -0,0 +1,23 @@
|
||||
===========
|
||||
Stuff To Do
|
||||
===========
|
||||
|
||||
----------------
|
||||
Working examples
|
||||
----------------
|
||||
|
||||
The examples from the Python 2 code base do not work and it appears
|
||||
that they don't under Python 2 either. These ought to be replaced or
|
||||
updated with examples from the GPGME documentation.
|
||||
|
||||
|
||||
-------------
|
||||
Documentation
|
||||
-------------
|
||||
|
||||
Currently this appears to be buried in the debian/ directory for some
|
||||
unknown reason, probably pertaining to one of the other developers.
|
||||
Documentation is to be moved to a more appropriate docs/ directory and
|
||||
produced using reST in preparation for inevitable publication by way
|
||||
of Sphinx and the existing infrastructure at readthedocs.org or the
|
||||
projects new home at gnupg.org.
|
2445
lang/python/docs/old-commits.log
Normal file
2445
lang/python/docs/old-commits.log
Normal file
File diff suppressed because it is too large
Load Diff
7
lang/python/examples/Examples.rst
Normal file
7
lang/python/examples/Examples.rst
Normal file
@ -0,0 +1,7 @@
|
||||
===============
|
||||
Example Scripts
|
||||
===============
|
||||
|
||||
Most of the examples have been converted to work with Python 3, just as the original versions worked with Python 2. A small number produce errors on OS X, but may behave differently on other POSIX systems. The GTK based scripts (PyGtkGpgKeys.py and pygpa.py) have not been modified at all.
|
||||
|
||||
When using or referring to the example scripts here, the most common change has been the byte encoded strings, so if something does not work then chances are that it will be related to the encoding or decoding of UTF-8.
|
36
lang/python/examples/delkey.py
Executable file
36
lang/python/examples/delkey.py
Executable file
@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env python3
|
||||
# $Id$
|
||||
# Copyright (C) 2004,2008 Igor Belyi <belyi@users.sourceforge.net>
|
||||
#
|
||||
# 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 2 of
|
||||
# the License, 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., 59 Temple Place, Suite 330, Boston, MA
|
||||
# 02111-1307 USA
|
||||
|
||||
# Sample of key deletion
|
||||
# It deletes keys for joe@example.org generated by genkey.pl script
|
||||
|
||||
from pyme import core
|
||||
|
||||
core.check_version(None)
|
||||
|
||||
# Note that we need to collect all keys out of the iterator return by
|
||||
# c.op_keylist_all() method before starting to delete them. If you
|
||||
# delete a key in the middle of iteration c.op_keylist_next() will
|
||||
# raise INV_VALUE exception
|
||||
|
||||
c = core.Context()
|
||||
# 0 in keylist means to list not only public but secret keys as well.
|
||||
for thekey in [x for x in c.op_keylist_all("joe+pyme@example.org", 0)]:
|
||||
# 1 in delete means to delete not only public but secret keys as well.
|
||||
c.op_delete(thekey, 1)
|
68
lang/python/examples/encrypt-to-all.py
Executable file
68
lang/python/examples/encrypt-to-all.py
Executable file
@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env python3
|
||||
# $Id$
|
||||
# Copyright (C) 2008 Igor Belyi <belyi@users.sourceforge.net>
|
||||
# Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
|
||||
#
|
||||
# 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 2 of
|
||||
# the License, 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., 59 Temple Place, Suite 330, Boston, MA
|
||||
# 02111-1307 USA
|
||||
|
||||
"""
|
||||
This program will try to encrypt a simple message to each key on your
|
||||
keyring. If your keyring has any invalid keys on it, those keys will
|
||||
be skipped and it will re-try the encryption."""
|
||||
|
||||
import sys
|
||||
import os
|
||||
from pyme import core
|
||||
from pyme.core import Data, Context
|
||||
|
||||
core.check_version(None)
|
||||
|
||||
plain = Data('This is my message.')
|
||||
|
||||
c = Context()
|
||||
c.set_armor(1)
|
||||
|
||||
def sendto(keylist):
|
||||
cipher = Data()
|
||||
c.op_encrypt(keylist, 1, plain, cipher)
|
||||
cipher.seek(0, os.SEEK_SET)
|
||||
return cipher.read()
|
||||
|
||||
names = []
|
||||
for key in c.op_keylist_all(None, 0):
|
||||
try:
|
||||
print(" *** Found key for %s" % key.uids[0].uid)
|
||||
valid = 0
|
||||
for subkey in key.subkeys:
|
||||
keyid = subkey.keyid
|
||||
if keyid is None:
|
||||
break
|
||||
can_encrypt = subkey.can_encrypt
|
||||
valid += can_encrypt
|
||||
print(" Subkey %s: encryption %s" %
|
||||
(keyid, can_encrypt and "enabled" or "disabled"))
|
||||
except UnicodeEncodeError as e:
|
||||
print(e)
|
||||
|
||||
if valid:
|
||||
names.append(key)
|
||||
else:
|
||||
print(" This key cannot be used for encryption; skipping.")
|
||||
|
||||
passno = 0
|
||||
|
||||
print("Encrypting to %d recipients" % len(names))
|
||||
sys.stdout.buffer.write(sendto(names))
|
76
lang/python/examples/exportimport.py
Executable file
76
lang/python/examples/exportimport.py
Executable file
@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env python3
|
||||
# $Id$
|
||||
# Copyright (C) 2004,2008 Igor Belyi <belyi@users.sourceforge.net>
|
||||
#
|
||||
# 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 2 of
|
||||
# the License, 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., 59 Temple Place, Suite 330, Boston, MA
|
||||
# 02111-1307 USA
|
||||
|
||||
# Sample of export and import of keys
|
||||
# It uses keys for joe@example.org generated by genkey.pl script
|
||||
|
||||
import sys
|
||||
from pyme import core
|
||||
|
||||
core.check_version(None)
|
||||
|
||||
expkey = core.Data()
|
||||
c = core.Context()
|
||||
c.set_armor(1)
|
||||
user = b"joe@example.org"
|
||||
|
||||
print(" - Export %s's public keys - " % user)
|
||||
c.op_export(user, 0, expkey)
|
||||
|
||||
# print out exported data to see how it looks in armor.
|
||||
expkey.seek(0, 0)
|
||||
expstring = expkey.read()
|
||||
if expstring:
|
||||
print(expstring)
|
||||
else:
|
||||
print("No %s's keys to export!" % user)
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
# delete keys to ensure that they came from our imported data.
|
||||
# Note that since joe's key has private part as well we can only delete
|
||||
# both of them. As a side effect joe won't have private key for this
|
||||
# exported public one. If it's Ok with you uncomment the next 4 lines.
|
||||
# print " - Delete %s's public keys - " % user
|
||||
# for thekey in [x for x in c.op_keylist_all(user, 0)]:
|
||||
# if not thekey.secret:
|
||||
# c.op_delete(thekey, 1)
|
||||
|
||||
|
||||
# initialize import data from a string as if it was read from a file.
|
||||
newkey = core.Data(expstring)
|
||||
|
||||
print(" - Import exported keys - ")
|
||||
c.op_import(newkey)
|
||||
result = c.op_import_result()
|
||||
|
||||
# show the import result
|
||||
if result:
|
||||
print(" - Result of the import - ")
|
||||
for k in dir(result):
|
||||
if k not in result.__dict__ and not k.startswith("_"):
|
||||
if k == "imports":
|
||||
print(k, ":")
|
||||
for impkey in result.__getattr__(k):
|
||||
print(" fpr=%s result=%d status=%x" %
|
||||
(impkey.fpr, impkey.result, impkey.status))
|
||||
else:
|
||||
print(k, ":", result.__getattr__(k))
|
||||
else:
|
||||
print(" - No import result - ")
|
45
lang/python/examples/genkey.py
Executable file
45
lang/python/examples/genkey.py
Executable file
@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env python3
|
||||
# $Id$
|
||||
# Copyright (C) 2004 Igor Belyi <belyi@users.sourceforge.net>
|
||||
# Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
|
||||
#
|
||||
# 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 2 of the License, 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
from pyme import core, callbacks
|
||||
|
||||
# Initialize our context.
|
||||
core.check_version(None)
|
||||
|
||||
c = core.Context()
|
||||
c.set_armor(1)
|
||||
c.set_progress_cb(callbacks.progress_stdout, None)
|
||||
|
||||
# This example from the GPGME manual
|
||||
|
||||
parms = """<GnupgKeyParms format="internal">
|
||||
Key-Type: RSA
|
||||
Key-Length: 2048
|
||||
Subkey-Type: RSA
|
||||
Subkey-Length: 2048
|
||||
Name-Real: Joe Tester
|
||||
Name-Comment: with stupid passphrase
|
||||
Name-Email: joe+pyme@example.org
|
||||
Passphrase: Crypt0R0cks
|
||||
Expire-Date: 2020-12-31
|
||||
</GnupgKeyParms>
|
||||
"""
|
||||
|
||||
c.op_genkey(parms, None, None)
|
||||
print(c.op_genkey_result().fpr)
|
59
lang/python/examples/inter-edit.py
Normal file
59
lang/python/examples/inter-edit.py
Normal file
@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env python3
|
||||
# $Id$
|
||||
# Copyright (C) 2005 Igor Belyi <belyi@users.sourceforge.net>
|
||||
#
|
||||
# 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 2 of the License, 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., 59 Temple Place, Suite 330, Boston, MA
|
||||
# 02111-1307 USA
|
||||
|
||||
import sys
|
||||
from pyme import core
|
||||
from pyme.core import Data, Context
|
||||
from pyme.constants import status
|
||||
|
||||
core.check_version(None)
|
||||
|
||||
# Get names for the status codes
|
||||
stat2str = {}
|
||||
for name in dir(status):
|
||||
if not name.startswith('__') and name != "util":
|
||||
stat2str[getattr(status, name)] = name
|
||||
|
||||
|
||||
# Print the output received since the last prompt before giving the new prompt
|
||||
def edit_fnc(stat, args, helper):
|
||||
global stat_strings
|
||||
try:
|
||||
while True:
|
||||
helper["data"].seek(helper["skip"], 0)
|
||||
data = helper["data"].read()
|
||||
helper["skip"] += len(data)
|
||||
sys.stdout.buffer.write(data)
|
||||
return input("(%s) %s > " % (stat2str[stat], args))
|
||||
except EOFError:
|
||||
pass
|
||||
|
||||
# Simple interactive editor to test editor scripts
|
||||
if len(sys.argv) != 2:
|
||||
sys.stderr.write("Usage: %s <Gpg key pattern>\n" % sys.argv[0])
|
||||
else:
|
||||
c = Context()
|
||||
out = Data()
|
||||
c.op_keylist_start(sys.argv[1], 0)
|
||||
key = c.op_keylist_next()
|
||||
helper = {"skip": 0, "data": out}
|
||||
c.op_edit(key, edit_fnc, helper, out)
|
||||
print("[-- Final output --]")
|
||||
out.seek(helper["skip"], 0)
|
||||
sys.stdout.buffer.write(out.read())
|
33
lang/python/examples/sign.py
Executable file
33
lang/python/examples/sign.py
Executable file
@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env python3
|
||||
# $Id$
|
||||
# Copyright (C) 2002 John Goerzen
|
||||
# <jgoerzen@complete.org>
|
||||
#
|
||||
# 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 2 of the License, 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
import sys
|
||||
import os
|
||||
from pyme import core, callbacks
|
||||
from pyme.constants.sig import mode
|
||||
|
||||
core.check_version(None)
|
||||
|
||||
plain = core.Data(b"Test message")
|
||||
sig = core.Data()
|
||||
c = core.Context()
|
||||
c.set_passphrase_cb(callbacks.passphrase_stdin, b'for signing')
|
||||
c.op_sign(plain, sig, mode.CLEAR)
|
||||
sig.seek(0, os.SEEK_SET)
|
||||
sys.stdout.buffer.write(sig.read())
|
78
lang/python/examples/signverify.py
Executable file
78
lang/python/examples/signverify.py
Executable file
@ -0,0 +1,78 @@
|
||||
#!/usr/bin/env python3
|
||||
# $Id$
|
||||
# Copyright (C) 2004,2008 Igor Belyi <belyi@users.sourceforge.net>
|
||||
#
|
||||
# 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 2 of the License, 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
# Sample of unattended signing/verifying of a message.
|
||||
# It uses keys for joe@example.org generated by genkey.pl script
|
||||
|
||||
import sys
|
||||
import os
|
||||
from pyme import core
|
||||
from pyme.constants.sig import mode
|
||||
|
||||
core.check_version(None)
|
||||
|
||||
plain = core.Data(b"Test message")
|
||||
sig = core.Data()
|
||||
c = core.Context()
|
||||
user = "joe"
|
||||
|
||||
c.signers_clear()
|
||||
# Add joe@example.org's keys in the list of signers
|
||||
for sigkey in c.op_keylist_all(user, 1):
|
||||
if sigkey.can_sign:
|
||||
c.signers_add(sigkey)
|
||||
if not c.signers_enum(0):
|
||||
print("No secret %s's keys suitable for signing!" % user)
|
||||
sys.exit(0)
|
||||
|
||||
# This is a map between signer e-mail and its password
|
||||
passlist = {
|
||||
b"<joe@example.org>": b"Crypt0R0cks"
|
||||
}
|
||||
|
||||
# callback will return password based on the e-mail listed in the hint.
|
||||
c.set_passphrase_cb(lambda x,y,z: passlist[x[x.rindex("<"):]])
|
||||
|
||||
c.op_sign(plain, sig, mode.CLEAR)
|
||||
|
||||
# Print out the signature (don't forget to rewind since signing put sig at EOF)
|
||||
sig.seek(0, os.SEEK_SET)
|
||||
signedtext = sig.read()
|
||||
sys.stdout.buffer.write(signedtext)
|
||||
|
||||
# Create Data with signed text.
|
||||
sig2 = core.Data(signedtext)
|
||||
plain2 = core.Data()
|
||||
|
||||
# Verify.
|
||||
c.op_verify(sig2, None, plain2)
|
||||
result = c.op_verify_result()
|
||||
|
||||
# List results for all signatures. Status equal 0 means "Ok".
|
||||
for index, sign in enumerate(result.signatures):
|
||||
print("signature", index, ":")
|
||||
print(" summary: ", sign.summary)
|
||||
print(" status: ", sign.status)
|
||||
print(" timestamp: ", sign.timestamp)
|
||||
print(" fingerprint:", sign.fpr)
|
||||
print(" uid: ", c.get_key(sign.fpr, 0).uids[0].uid)
|
||||
|
||||
# Print "unsigned" text. Rewind since verify put plain2 at EOF.
|
||||
plain2.seek(0, os.SEEK_SET)
|
||||
print("\n")
|
||||
sys.stdout.buffer.write(plain2.read())
|
53
lang/python/examples/simple.py
Executable file
53
lang/python/examples/simple.py
Executable file
@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env python3
|
||||
# $Id$
|
||||
# Copyright (C) 2005 Igor Belyi <belyi@users.sourceforge.net>
|
||||
# Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
|
||||
#
|
||||
# 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 2 of the License, 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
import sys
|
||||
import os
|
||||
from pyme import core, errors
|
||||
|
||||
core.check_version(None)
|
||||
|
||||
# Set up our input and output buffers.
|
||||
|
||||
plain = core.Data('This is my message.')
|
||||
cipher = core.Data()
|
||||
|
||||
# Initialize our context.
|
||||
|
||||
c = core.Context()
|
||||
c.set_armor(1)
|
||||
|
||||
# Set up the recipients.
|
||||
|
||||
sys.stdout.write("Enter name of your recipient: ")
|
||||
sys.stdout.flush()
|
||||
name = sys.stdin.readline().strip()
|
||||
c.op_keylist_start(name, 0)
|
||||
r = c.op_keylist_next()
|
||||
|
||||
if r == None:
|
||||
print("The key for user \"%s\" was not found" % name)
|
||||
else:
|
||||
# Do the encryption.
|
||||
try:
|
||||
c.op_encrypt([r], 1, plain, cipher)
|
||||
cipher.seek(0, os.SEEK_SET)
|
||||
sys.stdout.buffer.write(cipher.read())
|
||||
except errors.GPGMEError as ex:
|
||||
print(ex.getstring())
|
63
lang/python/examples/t-edit.py
Normal file
63
lang/python/examples/t-edit.py
Normal file
@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env python3
|
||||
# $Id$
|
||||
# Copyright (C) 2005 Igor Belyi <belyi@users.sourceforge.net>
|
||||
#
|
||||
# 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 2 of the License, 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
import sys
|
||||
import os
|
||||
from pyme import core
|
||||
from pyme.core import Data, Context
|
||||
|
||||
core.check_version(None)
|
||||
|
||||
class KeyEditor:
|
||||
def __init__(self):
|
||||
self.steps = ["fpr", "expire", "1", "primary", "quit"]
|
||||
self.step = 0
|
||||
|
||||
def edit_fnc(self, status, args, out):
|
||||
print("[-- Response --]")
|
||||
out.seek(0, os.SEEK_SET)
|
||||
sys.stdout.buffer.write(out.read())
|
||||
print("[-- Code: %d, %s --]" % (status, args))
|
||||
|
||||
if args == "keyedit.prompt":
|
||||
result = self.steps[self.step]
|
||||
self.step += 1
|
||||
elif args == "keyedit.save.okay":
|
||||
result = "Y"
|
||||
elif args == "keygen.valid":
|
||||
result = "0"
|
||||
else:
|
||||
result = None
|
||||
|
||||
return result
|
||||
|
||||
if not os.getenv("GNUPGHOME"):
|
||||
print("Please, set GNUPGHOME env.var. pointing to GPGME's tests/gpg dir")
|
||||
else:
|
||||
c = Context()
|
||||
c.set_passphrase_cb(lambda x,y,z: "abc")
|
||||
out = Data()
|
||||
c.op_keylist_start(b"Alpha", 0)
|
||||
key = c.op_keylist_next()
|
||||
if not key:
|
||||
sys.exit("Key Alpha not found. " +
|
||||
"Did you point GNUPGHOME to GPGME's tests/gpg dir?")
|
||||
c.op_edit(key, KeyEditor().edit_fnc, out, out)
|
||||
print("[-- Last response --]")
|
||||
out.seek(0, os.SEEK_SET)
|
||||
sys.stdout.buffer.write(out.read())
|
47
lang/python/examples/testCMSgetkey.py
Normal file
47
lang/python/examples/testCMSgetkey.py
Normal file
@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env python3
|
||||
# initial 20080124 bernhard@intevation.de
|
||||
# 20080124-2: removed some superflous imports
|
||||
# 20080703: adapted for pyme-0.8.0
|
||||
# This script is Free Software under GNU GPL v>=2.
|
||||
#
|
||||
# No modification made for python3 port, Bernhard can field this one
|
||||
# if it is still required. -- Ben McGinnes
|
||||
#
|
||||
"""A test applicaton for gpg_get_key() protocol.CMS.
|
||||
|
||||
Tested on Debian Etch with
|
||||
pyme 0.8.0 (manually compiled)
|
||||
libgpgme11 1.1.6-0kk2
|
||||
gpgsm 2.0.9-0kk2
|
||||
"""
|
||||
|
||||
import sys
|
||||
from pyme import core
|
||||
from pyme.constants import protocol
|
||||
|
||||
def printgetkeyresults(keyfpr):
|
||||
"""Run gpgme_get_key()."""
|
||||
|
||||
# gpgme_check_version() necessary for initialisation according to
|
||||
# gogme 1.1.6 and this is not done automatically in pyme-0.7.0
|
||||
print("gpgme version:", core.check_version(None))
|
||||
c = core.Context()
|
||||
c.set_protocol(protocol.CMS)
|
||||
|
||||
key = c.get_key(keyfpr, False)
|
||||
|
||||
print("got key: ", key.subkeys[0].fpr)
|
||||
|
||||
for uid in key.uids:
|
||||
print(uid.uid)
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print("fingerprint or unique key ID for gpgme_get_key()")
|
||||
sys.exit(1)
|
||||
|
||||
printgetkeyresults(sys.argv[1])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
97
lang/python/examples/verifydetails.py
Executable file
97
lang/python/examples/verifydetails.py
Executable file
@ -0,0 +1,97 @@
|
||||
#!/usr/bin/env python3
|
||||
# initial 20080123 build from the example:
|
||||
# very simple - probably INCOMPLETE
|
||||
# 20080703 Bernhard
|
||||
# added second usage for detached signatures.
|
||||
# added output of signature.summary (another bitfield)
|
||||
# printing signature bitfield in hex format
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
# Copyright (C) 2004,2008 Igor Belyi <belyi@users.sourceforge.net>
|
||||
# Copyright (c) 2008 Bernhard Reiter <bernhard@intevation.de>
|
||||
#
|
||||
# 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 2 of the License, 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import sys
|
||||
import os
|
||||
from pyme import core
|
||||
from pyme.constants import protocol
|
||||
|
||||
def print_engine_infos():
|
||||
print("gpgme version:", core.check_version(None))
|
||||
print("engines:")
|
||||
|
||||
for engine in core.get_engine_info():
|
||||
print(engine.file_name, engine.version)
|
||||
|
||||
for proto in [protocol.OpenPGP, protocol.CMS]:
|
||||
print(core.get_protocol_name(proto), core.engine_check_version(proto))
|
||||
|
||||
|
||||
def verifyprintdetails(sigfilename, filefilename=None):
|
||||
"""Verify a signature, print a lot of details."""
|
||||
c = core.Context()
|
||||
|
||||
# Create Data with signed text.
|
||||
sig2 = core.Data(file=sigfilename)
|
||||
if filefilename:
|
||||
file2 = core.Data(file=filefilename)
|
||||
plain2 = None
|
||||
else:
|
||||
file2 = None
|
||||
plain2 = core.Data()
|
||||
|
||||
# Verify.
|
||||
c.op_verify(sig2, file2, plain2)
|
||||
result = c.op_verify_result()
|
||||
|
||||
# List results for all signatures. Status equal 0 means "Ok".
|
||||
for index, sign in enumerate(result.signatures):
|
||||
print("signature", index, ":")
|
||||
print(" summary: %#0x" % (sign.summary))
|
||||
print(" status: %#0x" % (sign.status))
|
||||
print(" timestamp: ", sign.timestamp)
|
||||
print(" fingerprint:", sign.fpr)
|
||||
print(" uid: ", c.get_key(sign.fpr, 0).uids[0].uid)
|
||||
|
||||
# Print "unsigned" text if inline signature
|
||||
if plain2:
|
||||
#Rewind since verify put plain2 at EOF.
|
||||
plain2.seek(0, os.SEEK_SET)
|
||||
print("\n")
|
||||
sys.stdout.buffer.write(plain2.read())
|
||||
|
||||
def main():
|
||||
print_engine_infos()
|
||||
|
||||
print()
|
||||
|
||||
argc= len(sys.argv)
|
||||
if argc < 2 or argc > 3:
|
||||
print("need a filename for inline signature")
|
||||
print("or two filename for detached signature and file to check")
|
||||
sys.exit(1)
|
||||
|
||||
if argc == 2:
|
||||
print("trying to verify file: " + sys.argv[1])
|
||||
verifyprintdetails(sys.argv[1])
|
||||
if argc == 3:
|
||||
print("trying to verify signature %s for file %s" \
|
||||
% (sys.argv[1], sys.argv[2]))
|
||||
|
||||
verifyprintdetails(sys.argv[1], sys.argv[2])
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
42
lang/python/gpgme-h-clean.py
Executable file
42
lang/python/gpgme-h-clean.py
Executable file
@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env python3
|
||||
# $Id$
|
||||
# Copyright (C) 2004,2008 Igor Belyi <belyi@users.sourceforge.net>
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library 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
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
import sys, re
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
sys.stderr.write("Usage: %s gpgme.h\n" % sys.argv[0])
|
||||
sys.exit(1)
|
||||
|
||||
deprec_func=re.compile('^(.*typedef.*|.*\(.*\))\s*_GPGME_DEPRECATED;\s*',re.S)
|
||||
line_break=re.compile(';|\\$|\\x0c|^\s*#');
|
||||
try:
|
||||
gpgme = open(sys.argv[1])
|
||||
tmp = gpgme.readline()
|
||||
text = ''
|
||||
while tmp:
|
||||
text += re.sub(' class ', ' _py_obsolete_class ', tmp)
|
||||
if line_break.search(tmp):
|
||||
if not deprec_func.search(text):
|
||||
sys.stdout.write(text)
|
||||
text = ''
|
||||
tmp = gpgme.readline()
|
||||
sys.stdout.write(text)
|
||||
gpgme.close()
|
||||
except IOError as errmsg:
|
||||
sys.stderr.write("%s: %s\n" % (sys.argv[0], errmsg))
|
||||
sys.exit(1)
|
296
lang/python/gpgme.i
Normal file
296
lang/python/gpgme.i
Normal file
@ -0,0 +1,296 @@
|
||||
/*
|
||||
# $Id$
|
||||
# Copyright (C) 2004,2008 Igor Belyi <belyi@users.sourceforge.net>
|
||||
# Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library 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
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
%module pygpgme
|
||||
%include "cpointer.i"
|
||||
%include "cstring.i"
|
||||
|
||||
// Generate doc strings for all methods.
|
||||
%feature("autodoc", "0");
|
||||
|
||||
/* Allow use of Unicode objects, bytes, and None for strings. */
|
||||
|
||||
%typemap(in) const char * {
|
||||
if ($input == Py_None)
|
||||
$1 = NULL;
|
||||
else if (PyUnicode_Check($input))
|
||||
$1 = PyUnicode_AsUTF8($input);
|
||||
else if (PyBytes_Check($input))
|
||||
$1 = PyBytes_AsString($input);
|
||||
else {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"arg %d: expected str, bytes, or None, got %s",
|
||||
$argnum, $input->ob_type->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
%typemap(freearg) const char * "";
|
||||
|
||||
// Release returned buffers as necessary.
|
||||
%typemap(newfree) char * "free($1);";
|
||||
%newobject gpgme_data_release_and_get_mem;
|
||||
|
||||
%{
|
||||
/* Convert object to a pointer to gpgme type */
|
||||
PyObject* object_to_gpgme_t(PyObject* input, const char* objtype, int argnum) {
|
||||
PyObject *pyname = NULL, *pypointer = NULL;
|
||||
pyname = PyObject_CallMethod(input, "_getctype", NULL);
|
||||
if (pyname && PyUnicode_Check(pyname))
|
||||
{
|
||||
if (strcmp(PyUnicode_AsUTF8(pyname), objtype) != 0)
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"arg %d: Expected value of type %s, but got %s",
|
||||
argnum, objtype, PyUnicode_AsUTF8(pyname));
|
||||
Py_DECREF(pyname);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"Protocol violation: Expected an instance of type str "
|
||||
"from _getctype, but got %s",
|
||||
pyname == NULL ? "NULL"
|
||||
: (pyname == Py_None ? "None" : pyname->ob_type->tp_name));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_DECREF(pyname);
|
||||
pypointer = PyObject_GetAttrString(input, "wrapped");
|
||||
if (pypointer == NULL) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"arg %d: Use of uninitialized Python object %s",
|
||||
argnum, objtype);
|
||||
return NULL;
|
||||
}
|
||||
return pypointer;
|
||||
}
|
||||
%}
|
||||
|
||||
%typemap(arginit) gpgme_key_t [] {
|
||||
$1 = NULL;
|
||||
}
|
||||
|
||||
%typemap(in) gpgme_key_t [] {
|
||||
int i, numb = 0;
|
||||
if (!PySequence_Check($input)) {
|
||||
PyErr_Format(PyExc_ValueError, "arg %d: Expected a list of gpgme_key_t",
|
||||
$argnum);
|
||||
return NULL;
|
||||
}
|
||||
if((numb = PySequence_Length($input)) != 0) {
|
||||
$1 = (gpgme_key_t*)malloc((numb+1)*sizeof(gpgme_key_t));
|
||||
for(i=0; i<numb; i++) {
|
||||
PyObject *pypointer = PySequence_GetItem($input, i);
|
||||
|
||||
/* input = $input, 1 = $1, 1_descriptor = $1_descriptor */
|
||||
/* &1_descriptor = $&1_descriptor *1_descriptor = $*1_descriptor */
|
||||
|
||||
// Following code is from swig's python.swg
|
||||
if ((SWIG_ConvertPtr(pypointer,(void **) &$1[i], $*1_descriptor,SWIG_POINTER_EXCEPTION | $disown )) == -1) {
|
||||
Py_DECREF(pypointer);
|
||||
return NULL;
|
||||
}
|
||||
Py_DECREF(pypointer);
|
||||
}
|
||||
$1[numb] = NULL;
|
||||
}
|
||||
}
|
||||
%typemap(freearg) gpgme_key_t [] {
|
||||
if ($1) free($1);
|
||||
}
|
||||
|
||||
// Special handling for references to our objects.
|
||||
%typemap(in) gpgme_data_t DATAIN {
|
||||
if ($input == Py_None)
|
||||
$1 = NULL;
|
||||
else {
|
||||
PyObject *pypointer = NULL;
|
||||
|
||||
if((pypointer=object_to_gpgme_t($input, "$1_ltype", $argnum)) == NULL)
|
||||
return NULL;
|
||||
|
||||
/* input = $input, 1 = $1, 1_descriptor = $1_descriptor */
|
||||
|
||||
// Following code is from swig's python.swg
|
||||
|
||||
if ((SWIG_ConvertPtr(pypointer,(void **) &$1, $1_descriptor,
|
||||
SWIG_POINTER_EXCEPTION | $disown )) == -1) {
|
||||
Py_DECREF(pypointer);
|
||||
return NULL;
|
||||
}
|
||||
Py_DECREF(pypointer);
|
||||
}
|
||||
}
|
||||
|
||||
%apply gpgme_data_t DATAIN {gpgme_data_t plain, gpgme_data_t cipher,
|
||||
gpgme_data_t sig, gpgme_data_t signed_text,
|
||||
gpgme_data_t plaintext, gpgme_data_t keydata,
|
||||
gpgme_data_t pubkey, gpgme_data_t seckey,
|
||||
gpgme_data_t out};
|
||||
|
||||
// SWIG has problem interpreting ssize_t, off_t or gpgme_error_t in gpgme.h
|
||||
%typemap(out) ssize_t, off_t, gpgme_error_t, gpgme_err_code_t, gpgme_err_source_t, gpg_error_t {
|
||||
$result = PyLong_FromLong($1);
|
||||
}
|
||||
%typemap(in) ssize_t, off_t, gpgme_error_t, gpgme_err_code_t, gpgme_err_source_t, gpg_error_t {
|
||||
$1 = PyLong_AsLong($input);
|
||||
}
|
||||
|
||||
// Those are for gpgme_data_read() and gpgme_strerror_r()
|
||||
%typemap(in) (void *buffer, size_t size), (char *buf, size_t buflen) {
|
||||
$2 = PyLong_AsLong($input);
|
||||
if ($2 < 0) {
|
||||
PyErr_SetString(PyExc_ValueError, "Positive integer expected");
|
||||
return NULL;
|
||||
}
|
||||
$1 = ($1_ltype) malloc($2+1);
|
||||
}
|
||||
%typemap(argout) (void *buffer, size_t size), (char *buf, size_t buflen) {
|
||||
Py_XDECREF($result); /* Blow away any previous result */
|
||||
if (result < 0) { /* Check for I/O error */
|
||||
free($1);
|
||||
return NULL;
|
||||
}
|
||||
$result = PyBytes_FromStringAndSize($1,result);
|
||||
free($1);
|
||||
}
|
||||
|
||||
/* For gpgme_data_write, but should be universal. */
|
||||
%typemap(in) (const void *buffer, size_t size) {
|
||||
if ($input == Py_None)
|
||||
$1 = NULL, $2 = 0;
|
||||
else if (PyUnicode_Check($input))
|
||||
$1 = PyUnicode_AsUTF8AndSize($input, (size_t *) &$2);
|
||||
else if (PyBytes_Check($input))
|
||||
PyBytes_AsStringAndSize($input, (char **) &$1, (size_t *) &$2);
|
||||
else {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"arg %d: expected str, bytes, or None, got %s",
|
||||
$argnum, $input->ob_type->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
%typemap(freearg) (const void *buffer, size_t size) "";
|
||||
|
||||
// Make types containing 'next' field to be lists
|
||||
%ignore next;
|
||||
%typemap(out) gpgme_sig_notation_t, gpgme_engine_info_t, gpgme_subkey_t, gpgme_key_sig_t,
|
||||
gpgme_user_id_t, gpgme_invalid_key_t, gpgme_recipient_t, gpgme_new_signature_t,
|
||||
gpgme_signature_t, gpgme_import_status_t, gpgme_conf_arg_t, gpgme_conf_opt_t,
|
||||
gpgme_conf_comp_t {
|
||||
int i;
|
||||
int size = 0;
|
||||
$1_ltype curr;
|
||||
for (curr = $1; curr != NULL; curr = curr->next) {
|
||||
size++;
|
||||
}
|
||||
$result = PyList_New(size);
|
||||
for (i=0,curr=$1; i<size; i++,curr=curr->next) {
|
||||
PyObject *o = SWIG_NewPointerObj(SWIG_as_voidptr(curr), $1_descriptor, %newpointer_flags);
|
||||
PyList_SetItem($result, i, o);
|
||||
}
|
||||
}
|
||||
|
||||
// Include mapper for edit callbacks
|
||||
%typemap(in) (gpgme_edit_cb_t fnc, void *fnc_value) {
|
||||
$1 = (gpgme_edit_cb_t) pyEditCb;
|
||||
if ($input == Py_None)
|
||||
$2 = NULL;
|
||||
else
|
||||
$2 = $input;
|
||||
}
|
||||
|
||||
// Include the header file both for cc (first) and for swig (second)
|
||||
// Include for swig locally since we need to fix 'class' usage there.
|
||||
%{
|
||||
#include <gpgme.h>
|
||||
%}
|
||||
%include "gpgme.h"
|
||||
|
||||
%constant long EOF = GPG_ERR_EOF;
|
||||
|
||||
// Generating and handling pointers-to-pointers.
|
||||
|
||||
%pointer_functions(gpgme_ctx_t, gpgme_ctx_t_p);
|
||||
%pointer_functions(gpgme_data_t, gpgme_data_t_p);
|
||||
%pointer_functions(gpgme_key_t, gpgme_key_t_p);
|
||||
%pointer_functions(gpgme_error_t, gpgme_error_t_p);
|
||||
%pointer_functions(gpgme_trust_item_t, gpgme_trust_item_t_p);
|
||||
%pointer_functions(gpgme_engine_info_t, gpgme_engine_info_t_p);
|
||||
%pointer_functions(PyObject *, PyObject_p_p);
|
||||
%pointer_functions(void *, void_p_p);
|
||||
|
||||
// Helper functions.
|
||||
|
||||
%{
|
||||
#include <stdio.h>
|
||||
%}
|
||||
FILE *fdopen(int fildes, const char *mode);
|
||||
|
||||
%{
|
||||
#include "helpers.h"
|
||||
%}
|
||||
%include "helpers.h"
|
||||
|
||||
%{
|
||||
gpgme_error_t pyEditCb(void *opaque, gpgme_status_code_t status,
|
||||
const char *args, int fd) {
|
||||
PyObject *func = NULL, *dataarg = NULL, *pyargs = NULL, *retval = NULL;
|
||||
PyObject *pyopaque = (PyObject *) opaque;
|
||||
gpgme_error_t err_status = 0;
|
||||
|
||||
pygpgme_exception_init();
|
||||
|
||||
if (PyTuple_Check(pyopaque)) {
|
||||
func = PyTuple_GetItem(pyopaque, 0);
|
||||
dataarg = PyTuple_GetItem(pyopaque, 1);
|
||||
pyargs = PyTuple_New(3);
|
||||
} else {
|
||||
func = pyopaque;
|
||||
pyargs = PyTuple_New(2);
|
||||
}
|
||||
|
||||
PyTuple_SetItem(pyargs, 0, PyLong_FromLong((long) status));
|
||||
PyTuple_SetItem(pyargs, 1, PyUnicode_FromString(args));
|
||||
if (dataarg) {
|
||||
Py_INCREF(dataarg); /* Because GetItem doesn't give a ref but SetItem taketh away */
|
||||
PyTuple_SetItem(pyargs, 2, dataarg);
|
||||
}
|
||||
|
||||
retval = PyObject_CallObject(func, pyargs);
|
||||
Py_DECREF(pyargs);
|
||||
if (PyErr_Occurred()) {
|
||||
err_status = pygpgme_exception2code();
|
||||
} else {
|
||||
if (fd>=0 && retval && PyUnicode_Check(retval)) {
|
||||
const char *buffer;
|
||||
Py_ssize_t size;
|
||||
|
||||
buffer = PyUnicode_AsUTF8AndSize(retval, &size);
|
||||
write(fd, buffer, size);
|
||||
write(fd, "\n", 1);
|
||||
}
|
||||
}
|
||||
|
||||
Py_XDECREF(retval);
|
||||
return err_status;
|
||||
}
|
||||
%}
|
154
lang/python/helpers.c
Normal file
154
lang/python/helpers.c
Normal file
@ -0,0 +1,154 @@
|
||||
/*
|
||||
# $Id$
|
||||
# Copyright (C) 2004 Igor Belyi <belyi@users.sourceforge.net>
|
||||
# Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library 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
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <gpgme.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "Python.h"
|
||||
#include "helpers.h"
|
||||
|
||||
static PyObject *GPGMEError = NULL;
|
||||
|
||||
void pygpgme_exception_init(void) {
|
||||
if (GPGMEError == NULL) {
|
||||
PyObject *errors;
|
||||
errors = PyImport_ImportModule("errors");
|
||||
if (errors) {
|
||||
GPGMEError=PyDict_GetItemString(PyModule_GetDict(errors), "GPGMEError");
|
||||
Py_XINCREF(GPGMEError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gpgme_error_t pygpgme_exception2code(void) {
|
||||
gpgme_error_t err_status = gpg_error(GPG_ERR_GENERAL);
|
||||
if (GPGMEError && PyErr_ExceptionMatches(GPGMEError)) {
|
||||
PyObject *type = 0, *value = 0, *traceback = 0;
|
||||
PyObject *error = 0;
|
||||
PyErr_Fetch(&type, &value, &traceback);
|
||||
PyErr_NormalizeException(&type, &value, &traceback);
|
||||
error = PyObject_GetAttrString(value, "error");
|
||||
err_status = PyLong_AsLong(error);
|
||||
Py_DECREF(error);
|
||||
PyErr_Restore(type, value, traceback);
|
||||
}
|
||||
return err_status;
|
||||
}
|
||||
|
||||
void pygpgme_clear_generic_cb(PyObject **cb) {
|
||||
Py_DECREF(*cb);
|
||||
}
|
||||
|
||||
static gpgme_error_t pyPassphraseCb(void *hook,
|
||||
const char *uid_hint,
|
||||
const char *passphrase_info,
|
||||
int prev_was_bad,
|
||||
int fd) {
|
||||
PyObject *pyhook = (PyObject *) hook;
|
||||
PyObject *func = NULL;
|
||||
PyObject *args = NULL;
|
||||
PyObject *retval = NULL;
|
||||
PyObject *dataarg = NULL;
|
||||
gpgme_error_t err_status = 0;
|
||||
|
||||
pygpgme_exception_init();
|
||||
|
||||
if (PyTuple_Check(pyhook)) {
|
||||
func = PyTuple_GetItem(pyhook, 0);
|
||||
dataarg = PyTuple_GetItem(pyhook, 1);
|
||||
args = PyTuple_New(4);
|
||||
} else {
|
||||
func = pyhook;
|
||||
args = PyTuple_New(3);
|
||||
}
|
||||
|
||||
PyTuple_SetItem(args, 0, PyBytes_FromString(uid_hint));
|
||||
PyTuple_SetItem(args, 1, PyBytes_FromString(passphrase_info));
|
||||
PyTuple_SetItem(args, 2, PyBool_FromLong((long)prev_was_bad));
|
||||
if (dataarg) {
|
||||
Py_INCREF(dataarg); /* Because GetItem doesn't give a ref but SetItem taketh away */
|
||||
PyTuple_SetItem(args, 3, dataarg);
|
||||
}
|
||||
|
||||
retval = PyObject_CallObject(func, args);
|
||||
Py_DECREF(args);
|
||||
if (PyErr_Occurred()) {
|
||||
err_status = pygpgme_exception2code();
|
||||
} else {
|
||||
if (!retval) {
|
||||
write(fd, "\n", 1);
|
||||
} else {
|
||||
write(fd, PyBytes_AsString(retval), PyBytes_Size(retval));
|
||||
write(fd, "\n", 1);
|
||||
Py_DECREF(retval);
|
||||
}
|
||||
}
|
||||
|
||||
return err_status;
|
||||
}
|
||||
|
||||
void pygpgme_set_passphrase_cb(gpgme_ctx_t ctx, PyObject *cb,
|
||||
PyObject **freelater) {
|
||||
if (cb == Py_None) {
|
||||
gpgme_set_passphrase_cb(ctx, NULL, NULL);
|
||||
return;
|
||||
}
|
||||
Py_INCREF(cb);
|
||||
*freelater = cb;
|
||||
gpgme_set_passphrase_cb(ctx, (gpgme_passphrase_cb_t)pyPassphraseCb, (void *) cb);
|
||||
}
|
||||
|
||||
static void pyProgressCb(void *hook, const char *what, int type, int current,
|
||||
int total) {
|
||||
PyObject *func = NULL, *dataarg = NULL, *args = NULL, *retval = NULL;
|
||||
PyObject *pyhook = (PyObject *) hook;
|
||||
|
||||
if (PyTuple_Check(pyhook)) {
|
||||
func = PyTuple_GetItem(pyhook, 0);
|
||||
dataarg = PyTuple_GetItem(pyhook, 1);
|
||||
args = PyTuple_New(5);
|
||||
} else {
|
||||
func = pyhook;
|
||||
args = PyTuple_New(4);
|
||||
}
|
||||
|
||||
PyTuple_SetItem(args, 0, PyBytes_FromString(what));
|
||||
PyTuple_SetItem(args, 1, PyLong_FromLong((long) type));
|
||||
PyTuple_SetItem(args, 2, PyLong_FromLong((long) current));
|
||||
PyTuple_SetItem(args, 3, PyLong_FromLong((long) total));
|
||||
if (dataarg) {
|
||||
Py_INCREF(dataarg); /* Because GetItem doesn't give a ref but SetItem taketh away */
|
||||
PyTuple_SetItem(args, 4, dataarg);
|
||||
}
|
||||
|
||||
retval = PyObject_CallObject(func, args);
|
||||
Py_DECREF(args);
|
||||
Py_XDECREF(retval);
|
||||
}
|
||||
|
||||
void pygpgme_set_progress_cb(gpgme_ctx_t ctx, PyObject *cb, PyObject **freelater){
|
||||
if (cb == Py_None) {
|
||||
gpgme_set_progress_cb(ctx, NULL, NULL);
|
||||
return;
|
||||
}
|
||||
Py_INCREF(cb);
|
||||
*freelater = cb;
|
||||
gpgme_set_progress_cb(ctx, (gpgme_progress_cb_t) pyProgressCb, (void *) cb);
|
||||
}
|
36
lang/python/helpers.h
Normal file
36
lang/python/helpers.h
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
# $Id$
|
||||
# Copyright (C) 2004 Igor Belyi <belyi@users.sourceforge.net>
|
||||
# Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library 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
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include <gpgme.h>
|
||||
#include "Python.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#define write(fd, str, sz) {DWORD written; WriteFile((HANDLE) fd, str, sz, &written, 0);}
|
||||
#endif
|
||||
|
||||
void pygpgme_exception_init(void);
|
||||
gpgme_error_t pygpgme_exception2code(void);
|
||||
|
||||
void pygpgme_clear_generic_cb(PyObject **cb);
|
||||
|
||||
void pygpgme_set_passphrase_cb(gpgme_ctx_t ctx, PyObject *cb,
|
||||
PyObject **freelater);
|
||||
void pygpgme_set_progress_cb(gpgme_ctx_t ctx, PyObject *cb, PyObject **freelater);
|
139
lang/python/pyme/__init__.py
Normal file
139
lang/python/pyme/__init__.py
Normal file
@ -0,0 +1,139 @@
|
||||
# $Id$
|
||||
"""
|
||||
Pyme: GPGME Interface for Python
|
||||
Copyright (C) 2004 Igor Belyi <belyi@users.sourceforge.net>
|
||||
Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Welcome to PyME, the GPGME Interface for Python. "Pyme", when prounced,
|
||||
rhymes with "Pine".
|
||||
|
||||
The latest release of this package may be obtained from
|
||||
http://pyme.sourceforge.net
|
||||
Previous releases of this package can be obtained from
|
||||
http://quux.org/devel/pyme/
|
||||
|
||||
FEATURES
|
||||
--------
|
||||
|
||||
* Feature-rich, full implementation of the GPGME library. Supports
|
||||
all GPGME features except interactive editing (coming soon).
|
||||
Callback functions may be written in pure Python.
|
||||
|
||||
* Ability to sign, encrypt, decrypt, and verify data.
|
||||
|
||||
* Ability to list keys, export and import keys, and manage the keyring.
|
||||
|
||||
* Fully object-oriented with convenient classes and modules.
|
||||
|
||||
GENERAL OVERVIEW
|
||||
----------------
|
||||
|
||||
For those of you familiar with GPGME, you will be right at home here.
|
||||
|
||||
Pyme is, for the most part, a direct interface to the C GPGME
|
||||
library. However, it is re-packaged in a more Pythonic way --
|
||||
object-oriented with classes and modules. Take a look at the classes
|
||||
defined here -- they correspond directly to certain object types in GPGME
|
||||
for C. For instance, the following C code:
|
||||
|
||||
gpgme_ctx_t context;
|
||||
|
||||
gpgme_new(&context);
|
||||
|
||||
...
|
||||
gpgme_op_encrypt(context, recp, 1, plain, cipher);
|
||||
|
||||
Translates into the following Python code:
|
||||
|
||||
context = core.Context()
|
||||
...
|
||||
context.op_encrypt(recp, 1, plain, cipher)
|
||||
|
||||
The Python module automatically does error-checking and raises Python
|
||||
exception pyme.errors.GPGMEError when GPGME signals an error. getcode()
|
||||
and getsource() of this exception return code and source of the error.
|
||||
|
||||
IMPORTANT NOTE
|
||||
--------------
|
||||
This documentation only covers a small subset of available GPGME functions and
|
||||
methods. Please consult the documentation for the C library
|
||||
for comprehensive coverage.
|
||||
|
||||
This library uses Python's reflection to automatically detect the methods
|
||||
that are available for each class, and as such, most of those methods
|
||||
do not appear explicitly anywhere. You can use dir() python built-in command
|
||||
on an object to see what methods and fields it has but their meaning can
|
||||
be found only in GPGME documentation.
|
||||
|
||||
QUICK START SAMPLE PROGRAM
|
||||
--------------------------
|
||||
This program is not for serious encryption, but for example purposes only!
|
||||
|
||||
import sys
|
||||
import os
|
||||
from pyme import core, constants
|
||||
|
||||
# Set up our input and output buffers.
|
||||
|
||||
plain = core.Data('This is my message.')
|
||||
cipher = core.Data()
|
||||
|
||||
# Initialize our context.
|
||||
|
||||
c = core.Context()
|
||||
c.set_armor(1)
|
||||
|
||||
# Set up the recipients.
|
||||
|
||||
sys.stdout.write("Enter name of your recipient: ")
|
||||
sys.stdout.flush()
|
||||
name = sys.stdin.readline().strip()
|
||||
c.op_keylist_start(name, 0)
|
||||
r = c.op_keylist_next()
|
||||
|
||||
# Do the encryption.
|
||||
|
||||
c.op_encrypt([r], 1, plain, cipher)
|
||||
cipher.seek(0, os.SEEK_SET)
|
||||
sys.stdout.buffer.write(cipher.read())
|
||||
|
||||
Note that although there is no explicit error checking done here, the
|
||||
Python GPGME library is automatically doing error-checking, and will
|
||||
raise an exception if there is any problem.
|
||||
|
||||
This program is in the Pyme distribution as examples/simple.py. The examples
|
||||
directory contains more advanced samples as well.
|
||||
|
||||
FOR MORE INFORMATION
|
||||
--------------------
|
||||
PYME homepage: http://pyme.sourceforge.net
|
||||
GPGME documentation: http://pyme.sourceforge.net/doc/gpgme/index.html
|
||||
GPGME homepage: http://www.gnupg.org/gpgme.html
|
||||
|
||||
Base classes: pyme.core (START HERE!)
|
||||
Error classes: pyme.errors
|
||||
Constants: pyme.constants
|
||||
Version information: pyme.version
|
||||
Utilities: pyme.util
|
||||
|
||||
Base classes are documented at pyme.core.
|
||||
Classes of pyme.util usually are not instantiated by users
|
||||
directly but return by methods of base classes.
|
||||
|
||||
"""
|
||||
|
||||
__all__ = ['core', 'errors', 'constants', 'util', 'callbacks', 'version']
|
47
lang/python/pyme/callbacks.py
Normal file
47
lang/python/pyme/callbacks.py
Normal file
@ -0,0 +1,47 @@
|
||||
# $Id$
|
||||
# Copyright (C) 2004 Igor Belyi <belyi@users.sourceforge.net>
|
||||
# Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library 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
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
from getpass import getpass
|
||||
|
||||
def passphrase_stdin(hint, desc, prev_bad, hook=None):
|
||||
"""This is a sample callback that will read a passphrase from
|
||||
the terminal. The hook here, if present, will be used to describe
|
||||
why the passphrase is needed."""
|
||||
why = ''
|
||||
if hook != None:
|
||||
why = ' ' + hook
|
||||
if prev_bad:
|
||||
why += ' (again)'
|
||||
print("Please supply %s' password%s:" % (hint, why))
|
||||
return getpass()
|
||||
|
||||
def progress_stdout(what, type, current, total, hook=None):
|
||||
print("PROGRESS UPDATE: what = %s, type = %d, current = %d, total = %d" %\
|
||||
(what, type, current, total))
|
||||
|
||||
def readcb_fh(count, hook):
|
||||
"""A callback for data. hook should be a Python file-like object."""
|
||||
if count:
|
||||
# Should return '' on EOF
|
||||
return hook.read(count)
|
||||
else:
|
||||
# Wants to rewind.
|
||||
if not hasattr(hook, 'seek'):
|
||||
return None
|
||||
hook.seek(0, 0)
|
||||
return None
|
7
lang/python/pyme/constants/__init__.py
Normal file
7
lang/python/pyme/constants/__init__.py
Normal file
@ -0,0 +1,7 @@
|
||||
# $Id$
|
||||
|
||||
from pyme import util
|
||||
util.process_constants('GPGME_', globals())
|
||||
|
||||
__all__ = ['data', 'event', 'import', 'keylist', 'md', 'pk',
|
||||
'protocol', 'sig', 'sigsum', 'status', 'validity']
|
4
lang/python/pyme/constants/data/__init__.py
Normal file
4
lang/python/pyme/constants/data/__init__.py
Normal file
@ -0,0 +1,4 @@
|
||||
# $Id$
|
||||
|
||||
from . import encoding
|
||||
__all__ = ['encoding']
|
20
lang/python/pyme/constants/data/encoding.py
Normal file
20
lang/python/pyme/constants/data/encoding.py
Normal file
@ -0,0 +1,20 @@
|
||||
# $Id$
|
||||
# Copyright (C) 2004 Igor Belyi <belyi@users.sourceforge.net>
|
||||
# Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library 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
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
from pyme import util
|
||||
util.process_constants('GPGME_DATA_ENCODING_', globals())
|
20
lang/python/pyme/constants/event.py
Normal file
20
lang/python/pyme/constants/event.py
Normal file
@ -0,0 +1,20 @@
|
||||
# $Id$
|
||||
# Copyright (C) 2004 Igor Belyi <belyi@users.sourceforge.net>
|
||||
# Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library 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
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
from pyme import util
|
||||
util.process_constants('GPGME_EVENT_', globals())
|
20
lang/python/pyme/constants/import.py
Normal file
20
lang/python/pyme/constants/import.py
Normal file
@ -0,0 +1,20 @@
|
||||
# $Id$
|
||||
# Copyright (C) 2004 Igor Belyi <belyi@users.sourceforge.net>
|
||||
# Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library 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
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
from pyme import util
|
||||
util.process_constants('GPGME_IMPORT_', globals())
|
4
lang/python/pyme/constants/keylist/__init__.py
Normal file
4
lang/python/pyme/constants/keylist/__init__.py
Normal file
@ -0,0 +1,4 @@
|
||||
# $Id$
|
||||
|
||||
from . import mode
|
||||
__all__ = ['mode']
|
20
lang/python/pyme/constants/keylist/mode.py
Normal file
20
lang/python/pyme/constants/keylist/mode.py
Normal file
@ -0,0 +1,20 @@
|
||||
# $Id$
|
||||
# Copyright (C) 2004 Igor Belyi <belyi@users.sourceforge.net>
|
||||
# Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library 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
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
from pyme import util
|
||||
util.process_constants('GPGME_KEYLIST_MODE_', globals())
|
20
lang/python/pyme/constants/md.py
Normal file
20
lang/python/pyme/constants/md.py
Normal file
@ -0,0 +1,20 @@
|
||||
# $Id$
|
||||
# Copyright (C) 2004 Igor Belyi <belyi@users.sourceforge.net>
|
||||
# Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library 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
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
from pyme import util
|
||||
util.process_constants('GPGME_MD_', globals())
|
20
lang/python/pyme/constants/pk.py
Normal file
20
lang/python/pyme/constants/pk.py
Normal file
@ -0,0 +1,20 @@
|
||||
# $Id$
|
||||
# Copyright (C) 2004 Igor Belyi <belyi@users.sourceforge.net>
|
||||
# Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library 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
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
from pyme import util
|
||||
util.process_constants('GPGME_PK_', globals())
|
20
lang/python/pyme/constants/protocol.py
Normal file
20
lang/python/pyme/constants/protocol.py
Normal file
@ -0,0 +1,20 @@
|
||||
# $Id$
|
||||
# Copyright (C) 2004 Igor Belyi <belyi@users.sourceforge.net>
|
||||
# Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library 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
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
from pyme import util
|
||||
util.process_constants('GPGME_PROTOCOL_', globals())
|
4
lang/python/pyme/constants/sig/__init__.py
Normal file
4
lang/python/pyme/constants/sig/__init__.py
Normal file
@ -0,0 +1,4 @@
|
||||
# $Id$
|
||||
|
||||
from . import mode
|
||||
__all__ = ['mode']
|
20
lang/python/pyme/constants/sig/mode.py
Normal file
20
lang/python/pyme/constants/sig/mode.py
Normal file
@ -0,0 +1,20 @@
|
||||
# $Id$
|
||||
# Copyright (C) 2004 Igor Belyi <belyi@users.sourceforge.net>
|
||||
# Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library 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
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
from pyme import util
|
||||
util.process_constants('GPGME_SIG_MODE_', globals())
|
20
lang/python/pyme/constants/sigsum.py
Normal file
20
lang/python/pyme/constants/sigsum.py
Normal file
@ -0,0 +1,20 @@
|
||||
# $Id$
|
||||
# Copyright (C) 2004 Igor Belyi <belyi@users.sourceforge.net>
|
||||
# Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library 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
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
from pyme import util
|
||||
util.process_constants('GPGME_SIGSUM_', globals())
|
20
lang/python/pyme/constants/status.py
Normal file
20
lang/python/pyme/constants/status.py
Normal file
@ -0,0 +1,20 @@
|
||||
# $Id$
|
||||
# Copyright (C) 2004 Igor Belyi <belyi@users.sourceforge.net>
|
||||
# Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library 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
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
from pyme import util
|
||||
util.process_constants('GPGME_STATUS_', globals())
|
20
lang/python/pyme/constants/validity.py
Normal file
20
lang/python/pyme/constants/validity.py
Normal file
@ -0,0 +1,20 @@
|
||||
# $Id$
|
||||
# Copyright (C) 2004 Igor Belyi <belyi@users.sourceforge.net>
|
||||
# Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library 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
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
from pyme import util
|
||||
util.process_constants('GPGME_VALIDITY_', globals())
|
482
lang/python/pyme/core.py
Normal file
482
lang/python/pyme/core.py
Normal file
@ -0,0 +1,482 @@
|
||||
# $Id$
|
||||
# Copyright (C) 2004,2008 Igor Belyi <belyi@users.sourceforge.net>
|
||||
# Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library 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
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
# import generators for portability with python2.2
|
||||
|
||||
|
||||
from . import pygpgme
|
||||
from .errors import errorcheck, GPGMEError
|
||||
from . import errors
|
||||
from .util import GpgmeWrapper
|
||||
|
||||
class Context(GpgmeWrapper):
|
||||
"""From the GPGME C documentation:
|
||||
|
||||
* All cryptographic operations in GPGME are performed within a
|
||||
* context, which contains the internal state of the operation as well as
|
||||
* configuration parameters. By using several contexts you can run
|
||||
* several cryptographic operations in parallel, with different
|
||||
* configuration.
|
||||
|
||||
Thus, this is the place that you will usually start."""
|
||||
|
||||
def _getctype(self):
|
||||
return 'gpgme_ctx_t'
|
||||
|
||||
def _getnameprepend(self):
|
||||
return 'gpgme_'
|
||||
|
||||
def _errorcheck(self, name):
|
||||
"""This function should list all functions returning gpgme_error_t"""
|
||||
if (name.startswith('gpgme_op_') and \
|
||||
not name.endswith('_result')) or \
|
||||
name == 'gpgme_signers_add' or \
|
||||
name == 'gpgme_set_locale' or \
|
||||
name == 'gpgme_set_keylist_mode' or \
|
||||
name == 'gpgme_set_protocol':
|
||||
return 1
|
||||
return 0
|
||||
|
||||
def __init__(self, wrapped=None):
|
||||
if wrapped:
|
||||
self.wrapped = wrapped
|
||||
self.own = False
|
||||
else:
|
||||
tmp = pygpgme.new_gpgme_ctx_t_p()
|
||||
errorcheck(pygpgme.gpgme_new(tmp))
|
||||
self.wrapped = pygpgme.gpgme_ctx_t_p_value(tmp)
|
||||
pygpgme.delete_gpgme_ctx_t_p(tmp)
|
||||
self.own = True
|
||||
self.last_passcb = None
|
||||
self.last_progresscb = None
|
||||
|
||||
def __del__(self):
|
||||
if not pygpgme:
|
||||
# At interpreter shutdown, pygpgme is set to NONE.
|
||||
return
|
||||
|
||||
self._free_passcb()
|
||||
self._free_progresscb()
|
||||
if self.own and pygpgme.gpgme_release:
|
||||
pygpgme.gpgme_release(self.wrapped)
|
||||
|
||||
def _free_passcb(self):
|
||||
if self.last_passcb != None:
|
||||
if pygpgme.pygpgme_clear_generic_cb:
|
||||
pygpgme.pygpgme_clear_generic_cb(self.last_passcb)
|
||||
if pygpgme.delete_PyObject_p_p:
|
||||
pygpgme.delete_PyObject_p_p(self.last_passcb)
|
||||
self.last_passcb = None
|
||||
|
||||
def _free_progresscb(self):
|
||||
if self.last_progresscb != None:
|
||||
if pygpgme.pygpgme_clear_generic_cb:
|
||||
pygpgme.pygpgme_clear_generic_cb(self.last_progresscb)
|
||||
if pygpgme.delete_PyObject_p_p:
|
||||
pygpgme.delete_PyObject_p_p(self.last_progresscb)
|
||||
self.last_progresscb = None
|
||||
|
||||
def op_keylist_all(self, *args, **kwargs):
|
||||
self.op_keylist_start(*args, **kwargs)
|
||||
key = self.op_keylist_next()
|
||||
while key:
|
||||
yield key
|
||||
key = self.op_keylist_next()
|
||||
|
||||
def op_keylist_next(self):
|
||||
"""Returns the next key in the list created
|
||||
by a call to op_keylist_start(). The object returned
|
||||
is of type Key."""
|
||||
ptr = pygpgme.new_gpgme_key_t_p()
|
||||
try:
|
||||
errorcheck(pygpgme.gpgme_op_keylist_next(self.wrapped, ptr))
|
||||
key = pygpgme.gpgme_key_t_p_value(ptr)
|
||||
except errors.GPGMEError as excp:
|
||||
key = None
|
||||
if excp.getcode() != errors.EOF:
|
||||
raise excp
|
||||
pygpgme.delete_gpgme_key_t_p(ptr)
|
||||
if key:
|
||||
key.__del__ = lambda self: pygpgme.gpgme_key_unref(self)
|
||||
return key
|
||||
|
||||
def get_key(self, fpr, secret):
|
||||
"""Return the key corresponding to the fingerprint 'fpr'"""
|
||||
ptr = pygpgme.new_gpgme_key_t_p()
|
||||
errorcheck(pygpgme.gpgme_get_key(self.wrapped, fpr, ptr, secret))
|
||||
key = pygpgme.gpgme_key_t_p_value(ptr)
|
||||
pygpgme.delete_gpgme_key_t_p(ptr)
|
||||
if key:
|
||||
key.__del__ = lambda self: pygpgme.gpgme_key_unref(self)
|
||||
return key
|
||||
|
||||
def op_trustlist_all(self, *args, **kwargs):
|
||||
self.op_trustlist_start(*args, **kwargs)
|
||||
trust = self.ctx.op_trustlist_next()
|
||||
while trust:
|
||||
yield trust
|
||||
trust = self.ctx.op_trustlist_next()
|
||||
|
||||
def op_trustlist_next(self):
|
||||
"""Returns the next trust item in the list created
|
||||
by a call to op_trustlist_start(). The object returned
|
||||
is of type TrustItem."""
|
||||
ptr = pygpgme.new_gpgme_trust_item_t_p()
|
||||
try:
|
||||
errorcheck(pygpgme.gpgme_op_trustlist_next(self.wrapped, ptr))
|
||||
trust = pygpgme.gpgme_trust_item_t_p_value(ptr)
|
||||
except errors.GPGMEError as excp:
|
||||
trust = None
|
||||
if excp.getcode() != errors.EOF:
|
||||
raise
|
||||
pygpgme.delete_gpgme_trust_item_t_p(ptr)
|
||||
return trust
|
||||
|
||||
def set_passphrase_cb(self, func, hook=None):
|
||||
"""Sets the passphrase callback to the function specified by func.
|
||||
|
||||
When the system needs a passphrase, it will call func with three args:
|
||||
hint, a string describing the key it needs the passphrase for;
|
||||
desc, a string describing the passphrase it needs;
|
||||
prev_bad, a boolean equal True if this is a call made after
|
||||
unsuccessful previous attempt.
|
||||
|
||||
If hook has a value other than None it will be passed into the func
|
||||
as a forth argument.
|
||||
|
||||
Please see the GPGME manual for more information.
|
||||
"""
|
||||
self._free_passcb()
|
||||
if func == None:
|
||||
hookdata = None
|
||||
else:
|
||||
self.last_passcb = pygpgme.new_PyObject_p_p()
|
||||
if hook == None:
|
||||
hookdata = func
|
||||
else:
|
||||
hookdata = (func, hook)
|
||||
pygpgme.pygpgme_set_passphrase_cb(self.wrapped, hookdata, self.last_passcb)
|
||||
|
||||
def set_progress_cb(self, func, hook=None):
|
||||
"""Sets the progress meter callback to the function specified by
|
||||
|
||||
This function will be called to provide an interactive update of
|
||||
the system's progress.
|
||||
|
||||
Please see the GPGME manual for more information."""
|
||||
self._free_progresscb()
|
||||
if func == None:
|
||||
hookdata = None
|
||||
else:
|
||||
self.last_progresscb = pygpgme.new_PyObject_p_p()
|
||||
if hook == None:
|
||||
hookdata = func
|
||||
else:
|
||||
hookdata = (func, hook)
|
||||
pygpgme.pygpgme_set_progress_cb(self.wrapped, hookdata, self.last_progresscb)
|
||||
|
||||
def get_engine_info(self):
|
||||
"""Returns this context specific engine info"""
|
||||
return pygpgme.gpgme_ctx_get_engine_info(self.wrapped)
|
||||
|
||||
def set_engine_info(self, proto, file_name, home_dir=None):
|
||||
"""Changes the configuration of the crypto engine implementing the
|
||||
protocol 'proto' for the context. 'file_name' is the file name of
|
||||
the executable program implementing this protocol. 'home_dir' is the
|
||||
directory name of the configuration directory (engine's default is
|
||||
used if omitted)."""
|
||||
errorcheck(pygpgme.gpgme_ctx_set_engine_info(self.wrapped, proto, file_name, home_dir))
|
||||
|
||||
def wait(self, hang):
|
||||
"""Wait for asynchronous call to finish. Wait forever if hang is True
|
||||
|
||||
Return:
|
||||
On an async call completion its return status.
|
||||
On timeout - None.
|
||||
|
||||
Please read the GPGME manual for more information."""
|
||||
ptr = pygpgme.new_gpgme_error_t_p()
|
||||
context = pygpgme.gpgme_wait(self.wrapped, ptr, hang)
|
||||
status = pygpgme.gpgme_error_t_p_value(ptr)
|
||||
pygpgme.delete_gpgme_error_t_p(ptr)
|
||||
|
||||
if context == None:
|
||||
errorcheck(status)
|
||||
return None
|
||||
else:
|
||||
return status
|
||||
|
||||
def op_edit(self, key, func, fnc_value, out):
|
||||
"""Start key editing using supplied callback function"""
|
||||
if key == None:
|
||||
raise ValueError("op_edit: First argument cannot be None")
|
||||
opaquedata = (func, fnc_value)
|
||||
errorcheck(pygpgme.gpgme_op_edit(self.wrapped, key, opaquedata, out))
|
||||
|
||||
class Data(GpgmeWrapper):
|
||||
"""From the GPGME C manual:
|
||||
|
||||
* A lot of data has to be exchanged between the user and the crypto
|
||||
* engine, like plaintext messages, ciphertext, signatures and information
|
||||
* about the keys. The technical details about exchanging the data
|
||||
* information are completely abstracted by GPGME. The user provides and
|
||||
* receives the data via `gpgme_data_t' objects, regardless of the
|
||||
* communication protocol between GPGME and the crypto engine in use.
|
||||
|
||||
This Data class is the implementation of the GpgmeData objects.
|
||||
|
||||
Please see the information about __init__ for instantiation."""
|
||||
|
||||
def _getctype(self):
|
||||
return 'gpgme_data_t'
|
||||
|
||||
def _getnameprepend(self):
|
||||
return 'gpgme_data_'
|
||||
|
||||
def _errorcheck(self, name):
|
||||
"""This function should list all functions returning gpgme_error_t"""
|
||||
if name == 'gpgme_data_release_and_get_mem' or \
|
||||
name == 'gpgme_data_get_encoding' or \
|
||||
name == 'gpgme_data_seek':
|
||||
return 0
|
||||
return 1
|
||||
|
||||
def __init__(self, string = None, file = None, offset = None,
|
||||
length = None, cbs = None):
|
||||
"""Initialize a new gpgme_data_t object.
|
||||
|
||||
If no args are specified, make it an empty object.
|
||||
|
||||
If string alone is specified, initialize it with the data
|
||||
contained there.
|
||||
|
||||
If file, offset, and length are all specified, file must
|
||||
be either a filename or a file-like object, and the object
|
||||
will be initialized by reading the specified chunk from the file.
|
||||
|
||||
If cbs is specified, it MUST be a tuple of the form:
|
||||
|
||||
((read_cb, write_cb, seek_cb, release_cb), hook)
|
||||
|
||||
where func is a callback function taking two arguments (count,
|
||||
hook) and returning a string of read data, or None on EOF.
|
||||
This will supply the read() method for the system.
|
||||
|
||||
If file is specified without any other arguments, then
|
||||
it must be a filename, and the object will be initialized from
|
||||
that file.
|
||||
|
||||
Any other use will result in undefined or erroneous behavior."""
|
||||
self.wrapped = None
|
||||
self.last_readcb = None
|
||||
|
||||
if cbs != None:
|
||||
self.new_from_cbs(*cbs)
|
||||
elif string != None:
|
||||
self.new_from_mem(string)
|
||||
elif file != None and offset != None and length != None:
|
||||
self.new_from_filepart(file, offset, length)
|
||||
elif file != None:
|
||||
if type(file) == type("x"):
|
||||
self.new_from_file(file)
|
||||
else:
|
||||
self.new_from_fd(file)
|
||||
else:
|
||||
self.new()
|
||||
|
||||
def __del__(self):
|
||||
if not pygpgme:
|
||||
# At interpreter shutdown, pygpgme is set to NONE.
|
||||
return
|
||||
|
||||
if self.wrapped != None and pygpgme.gpgme_data_release:
|
||||
pygpgme.gpgme_data_release(self.wrapped)
|
||||
self._free_readcb()
|
||||
|
||||
def _free_readcb(self):
|
||||
if self.last_readcb != None:
|
||||
if pygpgme.pygpgme_clear_generic_cb:
|
||||
pygpgme.pygpgme_clear_generic_cb(self.last_readcb)
|
||||
if pygpgme.delete_PyObject_p_p:
|
||||
pygpgme.delete_PyObject_p_p(self.last_readcb)
|
||||
self.last_readcb = None
|
||||
|
||||
def new(self):
|
||||
tmp = pygpgme.new_gpgme_data_t_p()
|
||||
errorcheck(pygpgme.gpgme_data_new(tmp))
|
||||
self.wrapped = pygpgme.gpgme_data_t_p_value(tmp)
|
||||
pygpgme.delete_gpgme_data_t_p(tmp)
|
||||
|
||||
def new_from_mem(self, string, copy = 1):
|
||||
tmp = pygpgme.new_gpgme_data_t_p()
|
||||
errorcheck(pygpgme.gpgme_data_new_from_mem(tmp,string,len(string),copy))
|
||||
self.wrapped = pygpgme.gpgme_data_t_p_value(tmp)
|
||||
pygpgme.delete_gpgme_data_t_p(tmp)
|
||||
|
||||
def new_from_file(self, filename, copy = 1):
|
||||
tmp = pygpgme.new_gpgme_data_t_p()
|
||||
errorcheck(pygpgme.gpgme_data_new_from_file(tmp, filename, copy))
|
||||
self.wrapped = pygpgme.gpgme_data_t_p_value(tmp)
|
||||
pygpgme.delete_gpgme_data_t_p(tmp)
|
||||
|
||||
def new_from_cbs(self, funcs, hook):
|
||||
"""Argument funcs must be a 4 element tuple with callbacks:
|
||||
(read_cb, write_cb, seek_cb, release_cb)"""
|
||||
tmp = pygpgme.new_gpgme_data_t_p()
|
||||
self._free_readcb()
|
||||
self.last_readcb = pygpgme.new_PyObject_p_p()
|
||||
hookdata = (funcs, hook)
|
||||
pygpgme.pygpgme_data_new_from_cbs(tmp, hookdata, self.last_readcb)
|
||||
self.wrapped = pygpgme.gpgme_data_t_p_value(tmp)
|
||||
pygpgme.delete_gpgme_data_t_p(tmp)
|
||||
|
||||
def new_from_filepart(self, file, offset, length):
|
||||
"""This wraps the GPGME gpgme_data_new_from_filepart() function.
|
||||
The argument "file" may be:
|
||||
|
||||
1. a string specifying a file name, or
|
||||
3. a a file-like object. supporting the fileno() call and the mode
|
||||
attribute."""
|
||||
|
||||
tmp = pygpgme.new_gpgme_data_t_p()
|
||||
filename = None
|
||||
fp = None
|
||||
|
||||
if type(file) == type("x"):
|
||||
filename = file
|
||||
else:
|
||||
fp = pygpgme.fdopen(file.fileno(), file.mode)
|
||||
if fp == None:
|
||||
raise ValueError("Failed to open file from %s arg %s" % \
|
||||
(str(type(file)), str(file)))
|
||||
|
||||
errorcheck(pygpgme.gpgme_data_new_from_filepart(tmp, filename, fp,
|
||||
offset, length))
|
||||
self.wrapped = pygpgme.gpgme_data_t_p_value(tmp)
|
||||
pygpgme.delete_gpgme_data_t_p(tmp)
|
||||
|
||||
def new_from_fd(self, file):
|
||||
"""This wraps the GPGME gpgme_data_new_from_fd() function.
|
||||
The argument "file" may be a file-like object, supporting the fileno()
|
||||
call and the mode attribute."""
|
||||
|
||||
tmp = pygpgme.new_gpgme_data_t_p()
|
||||
fp = pygpgme.fdopen(file.fileno(), file.mode)
|
||||
if fp == None:
|
||||
raise ValueError("Failed to open file from %s arg %s" % \
|
||||
(str(type(file)), str(file)))
|
||||
errorcheck(pygpgme.gpgme_data_new_from_fd(tmp, fp))
|
||||
self.wrapped = pygpgme.gpgme_data_t_p_value(tmp)
|
||||
pygpgme.delete_gpgme_data_t_p(tmp)
|
||||
|
||||
def new_from_stream(self, file):
|
||||
"""This wrap around gpgme_data_new_from_stream is an alias for
|
||||
new_from_fd() method since in python there's not difference
|
||||
between file stream and file descriptor"""
|
||||
self.new_from_fd(file)
|
||||
|
||||
def write(self, buffer):
|
||||
"""Write buffer given as string or bytes.
|
||||
|
||||
If a string is given, it is implicitly encoded using UTF-8."""
|
||||
written = pygpgme.gpgme_data_write(self.wrapped, buffer)
|
||||
if written < 0:
|
||||
raise GPGMEError.fromSyserror()
|
||||
return written
|
||||
|
||||
def read(self, size = -1):
|
||||
"""Read at most size bytes, returned as bytes.
|
||||
|
||||
If the size argument is negative or omitted, read until EOF is reached.
|
||||
|
||||
Returns the data read, or the empty string if there was no data
|
||||
to read before EOF was reached."""
|
||||
|
||||
if size == 0:
|
||||
return ''
|
||||
|
||||
if size > 0:
|
||||
return pygpgme.gpgme_data_read(self.wrapped, size)
|
||||
else:
|
||||
chunks = []
|
||||
while 1:
|
||||
result = pygpgme.gpgme_data_read(self.wrapped, 4096)
|
||||
if len(result) == 0:
|
||||
break
|
||||
chunks.append(result)
|
||||
return b''.join(chunks)
|
||||
|
||||
def pubkey_algo_name(algo):
|
||||
return pygpgme.gpgme_pubkey_algo_name(algo)
|
||||
|
||||
def hash_algo_name(algo):
|
||||
return pygpgme.gpgme_hash_algo_name(algo)
|
||||
|
||||
def get_protocol_name(proto):
|
||||
return pygpgme.gpgme_get_protocol_name(proto)
|
||||
|
||||
def check_version(version=None):
|
||||
return pygpgme.gpgme_check_version(version)
|
||||
|
||||
def engine_check_version (proto):
|
||||
try:
|
||||
errorcheck(pygpgme.gpgme_engine_check_version(proto))
|
||||
return True
|
||||
except errors.GPGMEError:
|
||||
return False
|
||||
|
||||
def get_engine_info():
|
||||
ptr = pygpgme.new_gpgme_engine_info_t_p()
|
||||
try:
|
||||
errorcheck(pygpgme.gpgme_get_engine_info(ptr))
|
||||
info = pygpgme.gpgme_engine_info_t_p_value(ptr)
|
||||
except errors.GPGMEError:
|
||||
info = None
|
||||
pygpgme.delete_gpgme_engine_info_t_p(ptr)
|
||||
return info
|
||||
|
||||
def set_engine_info(proto, file_name, home_dir=None):
|
||||
"""Changes the default configuration of the crypto engine implementing
|
||||
the protocol 'proto'. 'file_name' is the file name of
|
||||
the executable program implementing this protocol. 'home_dir' is the
|
||||
directory name of the configuration directory (engine's default is
|
||||
used if omitted)."""
|
||||
errorcheck(pygpgme.gpgme_set_engine_info(proto, file_name, home_dir))
|
||||
|
||||
def set_locale(category, value):
|
||||
"""Sets the default locale used by contexts"""
|
||||
errorcheck(pygpgme.gpgme_set_locale(None, category, value))
|
||||
|
||||
def wait(hang):
|
||||
"""Wait for asynchronous call on any Context to finish.
|
||||
Wait forever if hang is True.
|
||||
|
||||
For finished anynch calls it returns a tuple (status, context):
|
||||
status - status return by asnynchronous call.
|
||||
context - context which caused this call to return.
|
||||
|
||||
Please read the GPGME manual of more information."""
|
||||
ptr = pygpgme.new_gpgme_error_t_p()
|
||||
context = pygpgme.gpgme_wait(None, ptr, hang)
|
||||
status = pygpgme.gpgme_error_t_p_value(ptr)
|
||||
pygpgme.delete_gpgme_error_t_p(ptr)
|
||||
if context == None:
|
||||
errorcheck(status)
|
||||
else:
|
||||
context = Context(context)
|
||||
return (status, context)
|
50
lang/python/pyme/errors.py
Normal file
50
lang/python/pyme/errors.py
Normal file
@ -0,0 +1,50 @@
|
||||
# $Id$
|
||||
# Copyright (C) 2004 Igor Belyi <belyi@users.sourceforge.net>
|
||||
# Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library 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
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
from . import pygpgme
|
||||
|
||||
class GPGMEError(Exception):
|
||||
def __init__(self, error = None, message = None):
|
||||
self.error = error
|
||||
self.message = message
|
||||
|
||||
@classmethod
|
||||
def fromSyserror(cls):
|
||||
return cls(pygpgme.gpgme_err_code_from_syserror())
|
||||
|
||||
def getstring(self):
|
||||
message = "%s: %s" % (pygpgme.gpgme_strsource(self.error),
|
||||
pygpgme.gpgme_strerror(self.error))
|
||||
if self.message != None:
|
||||
message = "%s: %s" % (self.message, message)
|
||||
return message
|
||||
|
||||
def getcode(self):
|
||||
return pygpgme.gpgme_err_code(self.error)
|
||||
|
||||
def getsource(self):
|
||||
return pygpgme.gpgme_err_source(self.error)
|
||||
|
||||
def __str__(self):
|
||||
return "%s (%d,%d)"%(self.getstring(), self.getsource(), self.getcode())
|
||||
|
||||
EOF = getattr(pygpgme, "EOF")
|
||||
|
||||
def errorcheck(retval, extradata = None):
|
||||
if retval:
|
||||
raise GPGMEError(retval, extradata)
|
97
lang/python/pyme/util.py
Normal file
97
lang/python/pyme/util.py
Normal file
@ -0,0 +1,97 @@
|
||||
# $Id$
|
||||
# Copyright (C) 2004,2008 Igor Belyi <belyi@users.sourceforge.net>
|
||||
# Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library 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
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
from . import pygpgme
|
||||
from .errors import errorcheck
|
||||
|
||||
def process_constants(starttext, dict):
|
||||
"""Called by the constant libraries to load up the appropriate constants
|
||||
from the C library."""
|
||||
index = len(starttext)
|
||||
for identifier in dir(pygpgme):
|
||||
if not identifier.startswith(starttext):
|
||||
continue
|
||||
name = identifier[index:]
|
||||
dict[name] = getattr(pygpgme, identifier)
|
||||
|
||||
class GpgmeWrapper(object):
|
||||
"""Base class all Pyme wrappers for GPGME functionality. Not to be
|
||||
instantiated directly."""
|
||||
def __repr__(self):
|
||||
return '<instance of %s.%s with GPG object at %s>' % \
|
||||
(__name__, self.__class__.__name__,
|
||||
self.wrapped)
|
||||
|
||||
def __str__(self):
|
||||
return repr(self)
|
||||
|
||||
def __hash__(self):
|
||||
return hash(repr(self.wrapped))
|
||||
|
||||
def __eq__(self, other):
|
||||
if other == None:
|
||||
return False
|
||||
else:
|
||||
return repr(self.wrapped) == repr(other.wrapped)
|
||||
|
||||
def _getctype(self):
|
||||
"""Must be implemented by child classes.
|
||||
|
||||
Must return the name of the c type."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def _getnameprepend(self):
|
||||
"""Must be implemented by child classes.
|
||||
|
||||
Must return the prefix of all c functions mapped to methods of
|
||||
this class."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def _errorcheck(self, name):
|
||||
"""Must be implemented by child classes.
|
||||
|
||||
This function must return a trueish value for all c functions
|
||||
returning gpgme_error_t."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def __getattr__(self, key):
|
||||
"""On-the-fly function generation."""
|
||||
if key[0] == '_' or self._getnameprepend() == None:
|
||||
return None
|
||||
name = self._getnameprepend() + key
|
||||
func = getattr(pygpgme, name)
|
||||
|
||||
if self._errorcheck(name):
|
||||
def _funcwrap(slf, *args, **kwargs):
|
||||
return errorcheck(func(slf.wrapped, *args, **kwargs),
|
||||
"Invocation of " + name)
|
||||
else:
|
||||
def _funcwrap(slf, *args, **kwargs):
|
||||
return func(slf.wrapped, *args, **kwargs)
|
||||
|
||||
_funcwrap.__doc__ = getattr(func, "__doc__")
|
||||
|
||||
# Monkey-patch the class.
|
||||
setattr(self.__class__, key, _funcwrap)
|
||||
|
||||
# Bind the method to 'self'.
|
||||
def wrapper(*args, **kwargs):
|
||||
return _funcwrap(self, *args, **kwargs)
|
||||
_funcwrap.__doc__ = getattr(func, "__doc__")
|
||||
|
||||
return wrapper
|
43
lang/python/pyme/version.py
Normal file
43
lang/python/pyme/version.py
Normal file
@ -0,0 +1,43 @@
|
||||
# $Id$
|
||||
|
||||
productname = 'pyme'
|
||||
versionstr = "0.9.1"
|
||||
revno = int('$Rev: 281 $'[6:-2])
|
||||
revstr = "Rev %d" % revno
|
||||
datestr = '$Date$'
|
||||
|
||||
versionlist = versionstr.split(".")
|
||||
major = versionlist[0]
|
||||
minor = versionlist[1]
|
||||
patch = versionlist[2]
|
||||
copyright = "Copyright (C) 2015 Ben McGinnes, 2014-2015 Martin Albrecht, 2004-2008 Igor Belyi, 2002 John Goerzen"
|
||||
author = "Ben McGinnes"
|
||||
author_email = "ben@adversary.org"
|
||||
description = "Python 3 support for GPGME GnuPG cryptography library"
|
||||
bigcopyright = """%(productname)s %(versionstr)s (%(revstr)s)
|
||||
%(copyright)s <%(author_email)s>""" % locals()
|
||||
|
||||
banner = bigcopyright + """
|
||||
This software comes with ABSOLUTELY NO WARRANTY; see the file
|
||||
COPYING for details. This is free software, and you are welcome
|
||||
to distribute it under the conditions laid out in COPYING."""
|
||||
|
||||
homepage = "https://gnupg.org"
|
||||
license = """Copyright (C) 2015 Ben McGinnes <ben@adversary.org>
|
||||
Copyright (C) 2014, 2015 Martin Albrecht <martinralbrecht@googlemail.com>
|
||||
Copyright (C) 2004, 2008 Igor Belyi <belyi@users.sourceforge.net>
|
||||
Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA"""
|
94
lang/python/setup.py
Executable file
94
lang/python/setup.py
Executable file
@ -0,0 +1,94 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# $Id$
|
||||
|
||||
# Module: installer
|
||||
# COPYRIGHT #
|
||||
# Copyright (C) 2004 Igor Belyi <belyi@users.sourceforge.net>
|
||||
# Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library 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
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
# END OF COPYRIGHT #
|
||||
|
||||
from distutils.core import setup, Extension
|
||||
import os, os.path, sys
|
||||
import subprocess
|
||||
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
import pyme.version
|
||||
|
||||
def getconfig(what):
|
||||
confdata = subprocess.Popen(["../../src/gpgme-config", "--%s" % what],
|
||||
stdout=subprocess.PIPE).communicate()[0]
|
||||
return [x for x in confdata.decode('utf-8').split() if x != '']
|
||||
|
||||
include_dirs = [os.getcwd()]
|
||||
define_macros = []
|
||||
library_dirs = ["../../src/.libs"] # XXX uses libtool internals
|
||||
libs = getconfig('libs')
|
||||
|
||||
for item in getconfig('cflags'):
|
||||
if item.startswith("-I"):
|
||||
include_dirs.append(item[2:])
|
||||
elif item.startswith("-D"):
|
||||
defitem = item[2:].split("=", 1)
|
||||
if len(defitem)==2:
|
||||
define_macros.append((defitem[0], defitem[1]))
|
||||
else:
|
||||
define_macros.append((defitem[0], None))
|
||||
|
||||
# Adjust include and library locations in case of win32
|
||||
uname_s = os.popen("uname -s").read()
|
||||
if uname_s.startswith("MINGW32"):
|
||||
mnts = [x.split()[0:3:2] for x in os.popen("mount").read().split("\n") if x]
|
||||
tmplist = sorted([(len(x[1]), x[1], x[0]) for x in mnts])
|
||||
tmplist.reverse()
|
||||
extra_dirs = []
|
||||
for item in include_dirs:
|
||||
for ln, mnt, tgt in tmplist:
|
||||
if item.startswith(mnt):
|
||||
item = os.path.normpath(item[ln:])
|
||||
while item[0] == os.path.sep:
|
||||
item = item[1:]
|
||||
extra_dirs.append(os.path.join(tgt, item))
|
||||
break
|
||||
include_dirs += extra_dirs
|
||||
for item in [x[2:] for x in libs if x.startswith("-L")]:
|
||||
for ln, mnt, tgt in tmplist:
|
||||
if item.startswith(mnt):
|
||||
item = os.path.normpath(item[ln:])
|
||||
while item[0] == os.path.sep:
|
||||
item = item[1:]
|
||||
library_dirs.append(os.path.join(tgt, item))
|
||||
break
|
||||
|
||||
swige = Extension("pyme._pygpgme", ["gpgme_wrap.c", "helpers.c"],
|
||||
include_dirs = include_dirs,
|
||||
define_macros = define_macros,
|
||||
library_dirs = library_dirs,
|
||||
extra_link_args = libs)
|
||||
|
||||
setup(name = "pyme",
|
||||
version=pyme.version.versionstr,
|
||||
description=pyme.version.description,
|
||||
author=pyme.version.author,
|
||||
author_email=pyme.version.author_email,
|
||||
url=pyme.version.homepage,
|
||||
ext_modules=[swige],
|
||||
packages = ['pyme', 'pyme.constants', 'pyme.constants.data',
|
||||
'pyme.constants.keylist', 'pyme.constants.sig'],
|
||||
license=pyme.version.copyright + \
|
||||
", Licensed under the GPL version 2 and the LGPL version 2.1"
|
||||
)
|
82
lang/python/tests/Makefile.am
Normal file
82
lang/python/tests/Makefile.am
Normal file
@ -0,0 +1,82 @@
|
||||
# Makefile.am for the tests of the Python bindings.
|
||||
# Copyright (C) 2016 g10 Code GmbH
|
||||
#
|
||||
# This file is part of GPGME.
|
||||
#
|
||||
# GPGME 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 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# GPGME 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 Lesser General
|
||||
# Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
GPG = gpg
|
||||
GPG_AGENT = gpg-agent
|
||||
export GNUPGHOME := $(abs_builddir)
|
||||
export GPG_AGENT_INFO :=
|
||||
|
||||
test_srcdir = $(top_srcdir)/tests/gpg
|
||||
|
||||
TESTS_ENVIRONMENT = GNUPGHOME=$(abs_builddir) \
|
||||
LC_ALL=C GPG_AGENT_INFO= \
|
||||
top_srcdir=$(top_srcdir) \
|
||||
PYTHONPATH=`echo $(abs_builddir)/../build/lib.*`
|
||||
|
||||
py_tests = t-wrapper.py \
|
||||
t-data.py \
|
||||
t-encrypt.py \
|
||||
t-decrypt.py
|
||||
|
||||
TESTS = $(top_srcdir)/tests/gpg/initial.test \
|
||||
$(py_tests) \
|
||||
$(top_srcdir)/tests/gpg/final.test
|
||||
|
||||
CLEANFILES = secring.gpg pubring.gpg pubring.kbx trustdb.gpg dirmngr.conf \
|
||||
gpg-agent.conf pubring.kbx~ gpg.conf pubring.gpg~ \
|
||||
random_seed .gpg-v21-migrated pubring-stamp
|
||||
|
||||
private_keys = \
|
||||
$(test_srcdir)/13CD0F3BDF24BE53FE192D62F18737256FF6E4FD \
|
||||
$(test_srcdir)/76F7E2B35832976B50A27A282D9B87E44577EB66 \
|
||||
$(test_srcdir)/A0747D5F9425E6664F4FFBEED20FBCA79FDED2BD \
|
||||
$(test_srcdir)/13CBE3758AFE42B5E5E2AE4CED27AFA455E3F87F \
|
||||
$(test_srcdir)/7A030357C0F253A5BBCD282FFC4E521B37558F5C
|
||||
|
||||
clean-local:
|
||||
-$(top_srcdir)/tests/start-stop-agent --stop
|
||||
-rm -fR -- private-keys-v1.d openpgp-revocs.d S.gpg-agent sshcontrol
|
||||
|
||||
check-local: ./gpg.conf ./gpg-agent.conf ./pubring-stamp \
|
||||
./private-keys-v1.d/gpg-sample.stamp
|
||||
|
||||
# To guarantee that check-local is run before any tests we
|
||||
# add this dependency:
|
||||
$(top_srcdir)/tests/gpg/initial.test: check-local
|
||||
|
||||
./private-keys-v1.d/gpg-sample.stamp: $(private_keys)
|
||||
test -d ./private-keys-v1.d || mkdir ./private-keys-v1.d
|
||||
for k in $(private_keys); do \
|
||||
cp $$k private-keys-v1.d/`basename $$k`.key; \
|
||||
done
|
||||
echo x > ./private-keys-v1.d/gpg-sample.stamp
|
||||
|
||||
./pubring-stamp: $(test_srcdir)/pubdemo.asc
|
||||
$(GPG) --no-permission-warning \
|
||||
--import $(test_srcdir)/pubdemo.asc
|
||||
-$(GPG) --no-permission-warning \
|
||||
--import $(test_srcdir)/secdemo.asc
|
||||
touch ./pubring-stamp
|
||||
|
||||
./gpg.conf:
|
||||
# This is required for t-sig-notations.
|
||||
echo no-force-v3-sigs > ./gpg.conf
|
||||
|
||||
./gpg-agent.conf:
|
||||
# This is required for gpg2, which does not support command fd.
|
||||
echo pinentry-program $(abs_top_srcdir)/tests/gpg/pinentry > ./gpg-agent.conf
|
26
lang/python/tests/support.py
Normal file
26
lang/python/tests/support.py
Normal file
@ -0,0 +1,26 @@
|
||||
# Copyright (C) 2016 g10 Code GmbH
|
||||
#
|
||||
# This file is part of GPGME.
|
||||
#
|
||||
# GPGME 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 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# GPGME 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 Lesser General
|
||||
# Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import os
|
||||
from pyme import core
|
||||
|
||||
def make_filename(name):
|
||||
return os.path.join(os.environ['top_srcdir'], 'tests', 'gpg', name)
|
||||
|
||||
def init_gpgme(proto):
|
||||
core.check_version()
|
||||
core.engine_check_version(proto)
|
49
lang/python/tests/t-data.py
Executable file
49
lang/python/tests/t-data.py
Executable file
@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Copyright (C) 2016 g10 Code GmbH
|
||||
#
|
||||
# This file is part of GPGME.
|
||||
#
|
||||
# GPGME 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 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# GPGME 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 Lesser General
|
||||
# Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import os
|
||||
|
||||
from pyme import core
|
||||
|
||||
data = core.Data('Hello world!')
|
||||
assert data.read() == b'Hello world!'
|
||||
assert data.read() == b''
|
||||
|
||||
data.seek(0, os.SEEK_SET)
|
||||
assert data.read() == b'Hello world!'
|
||||
assert data.read() == b''
|
||||
|
||||
data = core.Data(b'Hello world!')
|
||||
assert data.read() == b'Hello world!'
|
||||
|
||||
data = core.Data()
|
||||
data.write('Hello world!')
|
||||
data.seek(0, os.SEEK_SET)
|
||||
assert data.read() == b'Hello world!'
|
||||
|
||||
data = core.Data()
|
||||
data.write(b'Hello world!')
|
||||
data.seek(0, os.SEEK_SET)
|
||||
assert data.read() == b'Hello world!'
|
||||
|
||||
binjunk = bytes(range(256))
|
||||
data = core.Data()
|
||||
data.write(binjunk)
|
||||
data.seek(0, os.SEEK_SET)
|
||||
assert data.read() == binjunk
|
37
lang/python/tests/t-decrypt.py
Executable file
37
lang/python/tests/t-decrypt.py
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Copyright (C) 2016 g10 Code GmbH
|
||||
#
|
||||
# This file is part of GPGME.
|
||||
#
|
||||
# GPGME 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 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# GPGME 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 Lesser General
|
||||
# Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import sys
|
||||
import os
|
||||
from pyme import core, constants
|
||||
import support
|
||||
|
||||
support.init_gpgme(constants.PROTOCOL_OpenPGP)
|
||||
c = core.Context()
|
||||
|
||||
source = core.Data(file=support.make_filename("cipher-1.asc"))
|
||||
sink = core.Data()
|
||||
|
||||
c.op_decrypt(source, sink)
|
||||
result = c.op_decrypt_result()
|
||||
assert not result.unsupported_algorithm, \
|
||||
"Unsupported algorithm: {}".format(result.unsupported_algorithm)
|
||||
|
||||
sink.seek(0, os.SEEK_SET)
|
||||
sys.stdout.buffer.write(sink.read())
|
42
lang/python/tests/t-encrypt.py
Executable file
42
lang/python/tests/t-encrypt.py
Executable file
@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Copyright (C) 2016 g10 Code GmbH
|
||||
#
|
||||
# This file is part of GPGME.
|
||||
#
|
||||
# GPGME 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 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# GPGME 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 Lesser General
|
||||
# Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import sys
|
||||
import os
|
||||
from pyme import core, constants
|
||||
import support
|
||||
|
||||
support.init_gpgme(constants.PROTOCOL_OpenPGP)
|
||||
c = core.Context()
|
||||
c.set_armor(True)
|
||||
|
||||
source = core.Data("Hallo Leute\n")
|
||||
sink = core.Data()
|
||||
|
||||
keys = []
|
||||
keys.append(c.get_key("A0FF4590BB6122EDEF6E3C542D727CC768697734", False))
|
||||
keys.append(c.get_key("D695676BDCEDCC2CDD6152BCFE180B1DA9E3B0B2", False))
|
||||
|
||||
c.op_encrypt(keys, constants.ENCRYPT_ALWAYS_TRUST, source, sink)
|
||||
result = c.op_encrypt_result()
|
||||
assert not result.invalid_recipients, \
|
||||
"Invalid recipient encountered: {}".format(result.invalid_recipients.fpr)
|
||||
|
||||
sink.seek(0, os.SEEK_SET)
|
||||
sys.stdout.buffer.write(sink.read())
|
25
lang/python/tests/t-wrapper.py
Executable file
25
lang/python/tests/t-wrapper.py
Executable file
@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Copyright (C) 2016 g10 Code GmbH
|
||||
#
|
||||
# This file is part of GPGME.
|
||||
#
|
||||
# GPGME 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 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# GPGME 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 Lesser General
|
||||
# Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from pyme import core
|
||||
|
||||
d0 = core.Data()
|
||||
d0.seek # trigger on-demand-wrapping
|
||||
assert d0.seek == d0.seek, "Generated wrapper functions are not cached"
|
||||
assert hasattr(core.Data, 'seek'), "Generated wrapper functions are not shared"
|
135
m4/ax_pkg_swig.m4
Normal file
135
m4/ax_pkg_swig.m4
Normal file
@ -0,0 +1,135 @@
|
||||
# ===========================================================================
|
||||
# http://www.gnu.org/software/autoconf-archive/ax_pkg_swig.html
|
||||
# ===========================================================================
|
||||
#
|
||||
# SYNOPSIS
|
||||
#
|
||||
# AX_PKG_SWIG([major.minor.micro], [action-if-found], [action-if-not-found])
|
||||
#
|
||||
# DESCRIPTION
|
||||
#
|
||||
# This macro searches for a SWIG installation on your system. If found,
|
||||
# then SWIG is AC_SUBST'd; if not found, then $SWIG is empty. If SWIG is
|
||||
# found, then SWIG_LIB is set to the SWIG library path, and AC_SUBST'd.
|
||||
#
|
||||
# You can use the optional first argument to check if the version of the
|
||||
# available SWIG is greater than or equal to the value of the argument. It
|
||||
# should have the format: N[.N[.N]] (N is a number between 0 and 999. Only
|
||||
# the first N is mandatory.) If the version argument is given (e.g.
|
||||
# 1.3.17), AX_PKG_SWIG checks that the swig package is this version number
|
||||
# or higher.
|
||||
#
|
||||
# As usual, action-if-found is executed if SWIG is found, otherwise
|
||||
# action-if-not-found is executed.
|
||||
#
|
||||
# In configure.in, use as:
|
||||
#
|
||||
# AX_PKG_SWIG(1.3.17, [], [ AC_MSG_ERROR([SWIG is required to build..]) ])
|
||||
# AX_SWIG_ENABLE_CXX
|
||||
# AX_SWIG_MULTI_MODULE_SUPPORT
|
||||
# AX_SWIG_PYTHON
|
||||
#
|
||||
# LICENSE
|
||||
#
|
||||
# Copyright (c) 2008 Sebastian Huber <sebastian-huber@web.de>
|
||||
# Copyright (c) 2008 Alan W. Irwin
|
||||
# Copyright (c) 2008 Rafael Laboissiere <rafael@laboissiere.net>
|
||||
# Copyright (c) 2008 Andrew Collier
|
||||
# Copyright (c) 2011 Murray Cumming <murrayc@openismus.com>
|
||||
#
|
||||
# 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 2 of the License, 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, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# As a special exception, the respective Autoconf Macro's copyright owner
|
||||
# gives unlimited permission to copy, distribute and modify the configure
|
||||
# scripts that are the output of Autoconf when processing the Macro. You
|
||||
# need not follow the terms of the GNU General Public License when using
|
||||
# or distributing such scripts, even though portions of the text of the
|
||||
# Macro appear in them. The GNU General Public License (GPL) does govern
|
||||
# all other use of the material that constitutes the Autoconf Macro.
|
||||
#
|
||||
# This special exception to the GPL applies to versions of the Autoconf
|
||||
# Macro released by the Autoconf Archive. When you make and distribute a
|
||||
# modified version of the Autoconf Macro, you may extend this special
|
||||
# exception to the GPL to apply to your modified version as well.
|
||||
|
||||
#serial 11
|
||||
|
||||
AC_DEFUN([AX_PKG_SWIG],[
|
||||
# Ubuntu has swig 2.0 as /usr/bin/swig2.0
|
||||
AC_PATH_PROGS([SWIG],[swig swig2.0])
|
||||
if test -z "$SWIG" ; then
|
||||
m4_ifval([$3],[$3],[:])
|
||||
elif test -n "$1" ; then
|
||||
AC_MSG_CHECKING([SWIG version])
|
||||
[swig_version=`$SWIG -version 2>&1 | grep 'SWIG Version' | sed 's/.*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/g'`]
|
||||
AC_MSG_RESULT([$swig_version])
|
||||
if test -n "$swig_version" ; then
|
||||
# Calculate the required version number components
|
||||
[required=$1]
|
||||
[required_major=`echo $required | sed 's/[^0-9].*//'`]
|
||||
if test -z "$required_major" ; then
|
||||
[required_major=0]
|
||||
fi
|
||||
[required=`echo $required | sed 's/[0-9]*[^0-9]//'`]
|
||||
[required_minor=`echo $required | sed 's/[^0-9].*//'`]
|
||||
if test -z "$required_minor" ; then
|
||||
[required_minor=0]
|
||||
fi
|
||||
[required=`echo $required | sed 's/[0-9]*[^0-9]//'`]
|
||||
[required_patch=`echo $required | sed 's/[^0-9].*//'`]
|
||||
if test -z "$required_patch" ; then
|
||||
[required_patch=0]
|
||||
fi
|
||||
# Calculate the available version number components
|
||||
[available=$swig_version]
|
||||
[available_major=`echo $available | sed 's/[^0-9].*//'`]
|
||||
if test -z "$available_major" ; then
|
||||
[available_major=0]
|
||||
fi
|
||||
[available=`echo $available | sed 's/[0-9]*[^0-9]//'`]
|
||||
[available_minor=`echo $available | sed 's/[^0-9].*//'`]
|
||||
if test -z "$available_minor" ; then
|
||||
[available_minor=0]
|
||||
fi
|
||||
[available=`echo $available | sed 's/[0-9]*[^0-9]//'`]
|
||||
[available_patch=`echo $available | sed 's/[^0-9].*//'`]
|
||||
if test -z "$available_patch" ; then
|
||||
[available_patch=0]
|
||||
fi
|
||||
# Convert the version tuple into a single number for easier comparison.
|
||||
# Using base 100 should be safe since SWIG internally uses BCD values
|
||||
# to encode its version number.
|
||||
required_swig_vernum=`expr $required_major \* 10000 \
|
||||
\+ $required_minor \* 100 \+ $required_patch`
|
||||
available_swig_vernum=`expr $available_major \* 10000 \
|
||||
\+ $available_minor \* 100 \+ $available_patch`
|
||||
|
||||
if test $available_swig_vernum -lt $required_swig_vernum; then
|
||||
AC_MSG_WARN([SWIG version >= $1 is required. You have $swig_version.])
|
||||
SWIG=''
|
||||
m4_ifval([$3],[$3],[])
|
||||
else
|
||||
AC_MSG_CHECKING([for SWIG library])
|
||||
SWIG_LIB=`$SWIG -swiglib`
|
||||
AC_MSG_RESULT([$SWIG_LIB])
|
||||
m4_ifval([$2],[$2],[])
|
||||
fi
|
||||
else
|
||||
AC_MSG_WARN([cannot determine SWIG version])
|
||||
SWIG=''
|
||||
m4_ifval([$3],[$3],[])
|
||||
fi
|
||||
fi
|
||||
AC_SUBST([SWIG_LIB])
|
||||
])
|
64
m4/m4_ax_swig_python.m4
Normal file
64
m4/m4_ax_swig_python.m4
Normal file
@ -0,0 +1,64 @@
|
||||
# ===========================================================================
|
||||
# http://www.gnu.org/software/autoconf-archive/ax_swig_python.html
|
||||
# ===========================================================================
|
||||
#
|
||||
# SYNOPSIS
|
||||
#
|
||||
# AX_SWIG_PYTHON([use-shadow-classes = {no, yes}])
|
||||
#
|
||||
# DESCRIPTION
|
||||
#
|
||||
# Checks for Python and provides the $(AX_SWIG_PYTHON_CPPFLAGS), and
|
||||
# $(AX_SWIG_PYTHON_OPT) output variables.
|
||||
#
|
||||
# $(AX_SWIG_PYTHON_OPT) contains all necessary SWIG options to generate
|
||||
# code for Python. Shadow classes are enabled unless the value of the
|
||||
# optional first argument is exactly 'no'. If you need multi module
|
||||
# support (provided by the AX_SWIG_MULTI_MODULE_SUPPORT macro) use
|
||||
# $(AX_SWIG_PYTHON_LIBS) to link against the appropriate library. It
|
||||
# contains the SWIG Python runtime library that is needed by the type
|
||||
# check system for example.
|
||||
#
|
||||
# LICENSE
|
||||
#
|
||||
# Copyright (c) 2008 Sebastian Huber <sebastian-huber@web.de>
|
||||
# Copyright (c) 2008 Alan W. Irwin
|
||||
# Copyright (c) 2008 Rafael Laboissiere <rafael@laboissiere.net>
|
||||
# Copyright (c) 2008 Andrew Collier
|
||||
#
|
||||
# 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 2 of the License, 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, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# As a special exception, the respective Autoconf Macro's copyright owner
|
||||
# gives unlimited permission to copy, distribute and modify the configure
|
||||
# scripts that are the output of Autoconf when processing the Macro. You
|
||||
# need not follow the terms of the GNU General Public License when using
|
||||
# or distributing such scripts, even though portions of the text of the
|
||||
# Macro appear in them. The GNU General Public License (GPL) does govern
|
||||
# all other use of the material that constitutes the Autoconf Macro.
|
||||
#
|
||||
# This special exception to the GPL applies to versions of the Autoconf
|
||||
# Macro released by the Autoconf Archive. When you make and distribute a
|
||||
# modified version of the Autoconf Macro, you may extend this special
|
||||
# exception to the GPL to apply to your modified version as well.
|
||||
|
||||
#serial 10
|
||||
|
||||
AU_ALIAS([SWIG_PYTHON], [AX_SWIG_PYTHON])
|
||||
AC_DEFUN([AX_SWIG_PYTHON],[
|
||||
AC_REQUIRE([AX_PKG_SWIG])
|
||||
AC_REQUIRE([AX_PYTHON_DEVEL])
|
||||
test "x$1" != "xno" || swig_shadow=" -noproxy"
|
||||
AC_SUBST([AX_SWIG_PYTHON_OPT],[-python$swig_shadow])
|
||||
AC_SUBST([AX_SWIG_PYTHON_CPPFLAGS],[$PYTHON_CPPFLAGS])
|
||||
])
|
Loading…
Reference in New Issue
Block a user