monotone

monotone Mtn Source Tree

Root/cmd_packet.cc

1// Copyright (C) 2002 Graydon Hoare <graydon@pobox.com>
2//
3// This program is made available under the GNU GPL version 2.0 or
4// greater. See the accompanying file COPYING for details.
5//
6// This program is distributed WITHOUT ANY WARRANTY; without even the
7// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8// PURPOSE.
9
10#include <iostream>
11#include <sstream>
12
13#include "cmd.hh"
14#include "packet.hh"
15
16using std::cin;
17using std::cout;
18using std::istringstream;
19using std::vector;
20
21CMD(pubkey, N_("packet i/o"), N_("ID"),
22 N_("write public key packet to stdout"),
23 options::opts::none)
24{
25 if (args.size() != 1)
26 throw usage(name);
27
28 rsa_keypair_id ident(idx(args, 0)());
29 bool exists(false);
30 base64< rsa_pub_key > key;
31 if (app.db.database_specified() && app.db.public_key_exists(ident))
32 {
33 app.db.get_key(ident, key);
34 exists = true;
35 }
36 if (app.keys.key_pair_exists(ident))
37 {
38 keypair kp;
39 app.keys.get_key_pair(ident, kp);
40 key = kp.pub;
41 exists = true;
42 }
43 N(exists,
44 F("public key '%s' does not exist") % idx(args, 0)());
45
46 packet_writer pw(cout);
47 pw.consume_public_key(ident, key);
48}
49
50CMD(privkey, N_("packet i/o"), N_("ID"),
51 N_("write private key packet to stdout"),
52 options::opts::none)
53{
54 if (args.size() != 1)
55 throw usage(name);
56
57 rsa_keypair_id ident(idx(args, 0)());
58 N(app.keys.key_pair_exists(ident),
59 F("public and private key '%s' do not exist in keystore")
60 % idx(args, 0)());
61
62 packet_writer pw(cout);
63 keypair kp;
64 app.keys.get_key_pair(ident, kp);
65 pw.consume_key_pair(ident, kp);
66}
67
68
69CMD(read, N_("packet i/o"), "[FILE1 [FILE2 [...]]]",
70 N_("read packets from files or stdin"),
71 options::opts::none)
72{
73 packet_db_writer dbw(app);
74 size_t count = 0;
75 if (args.empty())
76 {
77 count += read_packets(cin, dbw, app);
78 N(count != 0, F("no packets found on stdin"));
79 }
80 else
81 {
82 for (vector<utf8>::const_iterator i = args.begin();
83 i != args.end(); ++i)
84 {
85 data dat;
86 read_data(system_path(*i), dat);
87 istringstream ss(dat());
88 count += read_packets(ss, dbw, app);
89 }
90 N(count != 0, FP("no packets found in given file",
91 "no packets found in given files",
92 args.size()));
93 }
94 P(FP("read %d packet", "read %d packets", count) % count);
95}
96
97
98// Local Variables:
99// mode: C++
100// fill-column: 76
101// c-file-style: "gnu"
102// indent-tabs-mode: nil
103// End:
104// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status