"SfR Fresh" - the SfR Freeware/Shareware Archive 
Member "vil96w32/gnugpg.rc" of archive vile-w32.zip:
As a special service "SfR Fresh" has tried to format the requested source page into HTML format using source code syntax highlighting with prefixed line numbers.
Alternatively you can here view or download the uninterpreted source code file.
That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
1 ; $Header: /usr/build/vile/vile/macros/RCS/gnugpg.rc,v 1.3 2004/12/16 00:37:09 tom Exp $
2
3 ; included below is a collection of macros that use GNU's gpg
4 ; encryption package in a win32 or Unix environment.
5
6 ; CAVEAT
7
8 ; These macros carefully minimize exposure of the user's
9 ; passphrase. For example, the passphrase is not echoed at
10 ; the keyboard and it's passed to gpg via a pipe (i.e., not on
11 ; the command line or from a disk file). However, when passed
12 ; via a pipe, the passphrase is visible for a short period of
13 ; time at the top of the current buffer. The duration of
14 ; exposure is directly proportional to the speed of the host
15 ; and its IPC implementation.
16
17 ; --------
18 ; use gpg to decrypt a disk file, storing the decrypted contents
19 ; in a scratch buffer that will be forgotten when the editor exits.
20 ; --------
21 store-procedure decrypt-file file="GPG-encrypted-file? "
22 ~if &seq '' $1
23 ~return
24 ~endif
25 ~local %tmpbuf %tmpfile %cmd %phrase
26 setv %phrase &qpasswd "GPG PassPhrase? "
27 ~if &error %phrase
28 ~return ; abort if cancel'd
29 ~endif
30 setv %phrase &cat %phrase "\n" ; this matters
31 setv %tmpbuf "[GPG scratch buffer]"
32 setv %tmpfile "GPG_scratch_buffer"
33
34 ; step 1, kill desired scratch buffer if it exists
35 ~force buffer %tmpbuf
36 ~if $status
37 unmark-buffer
38 ; switch to some other, existing buffer
39 buffer '[History]'
40 kill-buffer %tmpbuf
41 ~endif
42
43 ; step 2, create new instance of scratch buffer. Note that edit-file
44 ; won't open a file that looks like a scratch buffer if the latter
45 ; doesn't exist. workaround by simply renaming the buffer
46 edit-file %tmpfile
47 rename %tmpbuf
48
49 ; step 3, decrypt
50 setv %cmd="gpg --no-secmem-warning --batch --passphrase-fd 0 -d "
51 setv %cmd=&cat %cmd $1
52 insert-string %phrase
53 ~force up-line-at-bol
54 filter-til end-of-file %cmd
55 ; ensure scratch buffer disappears when editor exits, unless explicitly
56 ; written back by user
57 unmark-buffer
58 ~endm
59
60 ; --------
61 ; use gpg to decrypt the current buffer, marking the buffer as unmodified
62 ; so that its contents will be discarded when the editor exits.
63 ; --------
64 store-procedure decrypt-buffer
65 ~local %cmd %phrase
66 setv %phrase &qpasswd "GPG PassPhrase? "
67 ~if &error %phrase
68 ~return ; abort if cancel'd
69 ~endif
70 setv %phrase &cat %phrase "\n" ; this matters
71
72 setv %cmd="gpg --no-secmem-warning --batch --passphrase-fd 0 -d"
73 beginning-of-file
74 ; kill auto indent before inserting, else vile strips leading
75 ; whitespace from 1st line in buffer (don't know why)
76 ~local $autoindent
77 setv $autoindent=false
78 insert-string %phrase
79 ~force up-line-at-bol
80 filter-til end-of-file %cmd
81 ; ensure buffer disappears when editor exits, unless explicitly written
82 ; back by user
83 unmark-buffer
84 ~endm
85
86 ; use gpg to symmetrically encrypt the current buffer
87 store-procedure encrypt-buffer file="Destination filename? "
88 ~if &seq '' $1
89 ~return
90 ~endif
91 ~local %cmd %phrase1 %phrase2
92 setv %phrase1 &qpasswd "GPG PassPhrase? "
93 ~if &error %phrase1
94 ~return ; abort if cancel'd
95 ~endif
96 setv %phrase2 &qpasswd "Repeat PassPhrase: "
97 ~if &error %phrase2
98 ~return ; abort if cancel'd
99 ~endif
100 ~if ¬ &seq %phrase2 %phrase1
101 write-message "PassPhrase mismatch"
102 ~return
103 ~endif
104 setv %phrase1 &cat %phrase1 "\n" ; this matters
105 setv %cmd="gpg --no-secmem-warning -ac --batch --passphrase-fd 0"
106 beginning-of-file
107 ; kill auto indent before inserting, else vile strips leading
108 ; whitespace from 1st line in buffer (don't know why)
109 ~local $autoindent
110 setv $autoindent=false
111 insert-string %phrase1
112 ~force up-line-at-bol
113 filter-til end-of-file %cmd
114 ; make current buffer names match filename selected above
115 ~if ¬ &seq $cbufname $1
116 rename $1
117 ~endif
118 file $1
119 ~endm
120
121 ; --------
122 ; use gpg to clearsign the current buffer (useful for posting
123 ; gpg-signed USENET articles)
124 ; --------
125 store-procedure clearsign
126 ~local %cmd %phrase
127 setv %phrase &qpasswd "GPG PassPhrase? "
128 ~if &error %phrase
129 ~return ; abort if cancel'd
130 ~endif
131 setv %phrase &cat %phrase "\n" ; this matters
132 setv %cmd="gpg --no-secmem-warning --clearsign --batch --passphrase-fd 0"
133 beginning-of-file
134 ; kill auto indent before inserting, else vile strips leading
135 ; whitespace from 1st line in buffer (don't know why)
136 ~local $autoindent
137 setv $autoindent=false
138 insert-string %phrase
139 ~force up-line-at-bol
140 filter-til end-of-file %cmd
141 ~endm