TclGPG  Check-in [e0cfba5122]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Added option -keys to the import routine.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:e0cfba5122cb7457d9a6b0357139940f9f4ff1ac
User & Date: sgolovan 2015-12-30 11:41:52
Context
2015-12-31
20:12
Explicitly unset the GPG_AGENT_INFO environment variable because it interferes with tests. check-in: 6361d617e5 user: sergei tags: trunk
2015-12-30
11:41
Added option -keys to the import routine. check-in: e0cfba5122 user: sgolovan tags: trunk
09:14
Added incomplete (but usable) support for importing and deleting GPG keys. Bumped the package version to 1.1. check-in: 7786c1df95 user: sgolovan tags: trunk
Changes

Changes to ChangeLog.

1
2
3
4
5
6


7
8
9
10
11
12
13
2015-12-30  Sergei Golovan  <sgolovan@nes.ru>

	* tclgpg.tcl, tclgpg.test: Added incomplete (but usable) support for
	  importing and deleting GPG keys.

	* configure.in: Bumped the package version to 1.1.



2015-12-27  Sergei Golovan  <sgolovan@nes.ru>

	* tclgpg.tcl: Return the 'bad passphrase' error for the case of
	  failure after incorrectly entered passphrase via the pinentry.

	* tclgpg.test: Added a test which ensures that the recipient for






>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2015-12-30  Sergei Golovan  <sgolovan@nes.ru>

	* tclgpg.tcl, tclgpg.test: Added incomplete (but usable) support for
	  importing and deleting GPG keys.

	* configure.in: Bumped the package version to 1.1.

	* tclgpg.tcl, tclgpg.test: Added option -keys to the import routine.

2015-12-27  Sergei Golovan  <sgolovan@nes.ru>

	* tclgpg.tcl: Return the 'bad passphrase' error for the case of
	  failure after incorrectly entered passphrase via the pinentry.

	* tclgpg.test: Added a test which ensures that the recipient for

Changes to tclgpg.tcl.

656
657
658
659
660
661
662

663
664
665
666
667
668
669
670






671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688

689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713

proc ::gpg::Import {token args} {
    variable $token
    upvar 0 $token state

    set commands {}
    set opts {}


    foreach {key val} $args {
        switch -- $key {
            -keyserver {
                set opts [list --keyserver $val]
            }
            -key {
                set arg $val






                set operation --recv-keys
            }
            -uri {
                set arg $val
                set operation --fetch-keys
            }
            -data {
                set arg $val
                set operation --import
            }
            -command {
                set commands [list $val]
            }
            default {
                return -code error \
                       [format "unknown option \"%s\":\
                                must be %s" $key [JoinOptions {-keyserver
                                                               -key

                                                               -uri
                                                               -data
                                                               -command}]]
            }
        }
    }

    if {![info exists operation]} {
        return -code error "one of -key, -uri, or -data options must\
                            be specified"
    }

    if {$operation eq "--import"} {
        set gpgChannels [ExecGPG $token import --batch --import]
        return [UseGPG $token import $commands $gpgChannels $arg]
    } else {
        set gpgChannels [eval ExecGPG $token fetch --batch $opts $operation \
                              -- [list $arg]]
        return [UseGPG $token fetch $commands $gpgChannels]
    }
}

# ::gpg::Delete --
#
#       Delete key from the keyring.







>







|
>
>
>
>
>
>



|



|










>








|





|


|







656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721

proc ::gpg::Import {token args} {
    variable $token
    upvar 0 $token state

    set commands {}
    set opts {}
    set arg {}

    foreach {key val} $args {
        switch -- $key {
            -keyserver {
                set opts [list --keyserver $val]
            }
            -key {
                lappend arg $val
                set operation --recv-keys
            }
            -keys {
                foreach v $val {
                    lappend arg $v
                }
                set operation --recv-keys
            }
            -uri {
                set arg [list $val]
                set operation --fetch-keys
            }
            -data {
                set input $val
                set operation --import
            }
            -command {
                set commands [list $val]
            }
            default {
                return -code error \
                       [format "unknown option \"%s\":\
                                must be %s" $key [JoinOptions {-keyserver
                                                               -key
                                                               -keys
                                                               -uri
                                                               -data
                                                               -command}]]
            }
        }
    }

    if {![info exists operation]} {
        return -code error "one of -key, -keys, -uri, or -data options must\
                            be specified"
    }

    if {$operation eq "--import"} {
        set gpgChannels [ExecGPG $token import --batch --import]
        return [UseGPG $token import $commands $gpgChannels $input]
    } else {
        set gpgChannels [eval ExecGPG $token fetch --batch $opts $operation \
                              -- $arg]
        return [UseGPG $token fetch $commands $gpgChannels]
    }
}

# ::gpg::Delete --
#
#       Delete key from the keyring.

Changes to tclgpg.test.

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
...
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617

set auto_path [linsert $auto_path 0 [file dirname [info script]]]

set env(GNUPGHOME) [file join [file dirname [info script]] gnupg]
catch {file attributes $env(GNUPGHOME) -permissions 0700}

package forget gpg
package require -exact gpg 1.0

test new-1.1 {Create context} -body {
    set c [::gpg::new]
    list [string equal [info procs $c] $c] \
                  [string equal [info vars $c] $c]
} -result {1 1} -cleanup {$c free}

................................................................................

test import-1.1 {Import with unknown option} -body {
    set c [::gpg::new]
    $c import -email user@host
} -cleanup {
    $c free
} -returnCodes error \
-result {unknown option "-email": must be -keyserver, -key, -uri, -data, or -command}

test import-1.2 {Import without required option} -body {
    set c [::gpg::new]
    $c import -keyserver pgp.mit.edu
} -cleanup {
    $c free
} -returnCodes error -result {one of -key, -uri, or -data options must be specified}

test import-1.3 {Import invalid data using -data} -body {
    set c [::gpg::new]
    $c import -data "garbage"
} -cleanup {
    $c free
} -returnCodes error -result {Invalid data to import}







|







 







|






|







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
...
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617

set auto_path [linsert $auto_path 0 [file dirname [info script]]]

set env(GNUPGHOME) [file join [file dirname [info script]] gnupg]
catch {file attributes $env(GNUPGHOME) -permissions 0700}

package forget gpg
package require -exact gpg 1.1

test new-1.1 {Create context} -body {
    set c [::gpg::new]
    list [string equal [info procs $c] $c] \
                  [string equal [info vars $c] $c]
} -result {1 1} -cleanup {$c free}

................................................................................

test import-1.1 {Import with unknown option} -body {
    set c [::gpg::new]
    $c import -email user@host
} -cleanup {
    $c free
} -returnCodes error \
-result {unknown option "-email": must be -keyserver, -key, -keys, -uri, -data, or -command}

test import-1.2 {Import without required option} -body {
    set c [::gpg::new]
    $c import -keyserver pgp.mit.edu
} -cleanup {
    $c free
} -returnCodes error -result {one of -key, -keys, -uri, or -data options must be specified}

test import-1.3 {Import invalid data using -data} -body {
    set c [::gpg::new]
    $c import -data "garbage"
} -cleanup {
    $c free
} -returnCodes error -result {Invalid data to import}