1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/base/DrunkenBishop.h
11 #ifndef ZYPP_BASE_DRUNKENBISHOP_H
12 #define ZYPP_BASE_DRUNKENBISHOP_H
18 #include "zypp/base/PtrTypes.h"
19 #include "zypp/base/Flags.h"
21 ///////////////////////////////////////////////////////////////////
24 ///////////////////////////////////////////////////////////////////
27 ///////////////////////////////////////////////////////////////////
28 /// \class DrunkenBishop
29 /// \brief Random art fingerprint visualization
30 /// Visualize fingerprint data on a [17x9] (SSH) or [19x11] (GPG) or
31 /// custom sized board. The default board size and layout depends on
32 /// the data string length (above 32 the GPG board and layout is used).
34 /// The data string should be an even sized HEX string, otherwise
35 /// it will be 0-padded.
37 /// All ctor calls may throw \ref std::invalid_argument.
40 /// [SuSE Package Signing Key <build@suse.de>]
41 /// +------[Title]------+
42 /// | . . ^ | fpr FEAB502539D846DB2C0961CA70AF9E8139DB7C82
43 /// | : : . | id 70AF9E8139DB7C82
44 /// | ^ ^ . | cre 1481108255 Wed Dec 7 11:57:35 2016
45 /// | ^ . l i | exp 1607252255 Sun Dec 6 11:57:35 2020
46 /// | : ^ . f : | ttl 992
47 /// | ? ^ .Sl | rpm 39db7c82-5847eb1f
53 /// +----[39DB7C82]-----+
56 /// Based on https://github.com/atoponce/keyart, the development location
57 /// for the Debian signing-party package. We try to use the same charset
59 /// See also http://dirk-loss.de/sshvis/drunken_bishop.pdf.
60 ///////////////////////////////////////////////////////////////////
63 friend std::ostream & operator<<( std::ostream & str, const DrunkenBishop & obj );
66 /** Default ctor: empty board (1x1) */
69 /** Ctor taking a data string (and optional title) and using a default (SSH/GPG) board. */
70 DrunkenBishop( const std::string & data_r, const std::string & title_r = std::string() );
72 /** Ctor also taking a desired board height (even value is incremented, width is 2*height-1). */
73 DrunkenBishop( const std::string & data_r, const std::string & title_r, unsigned height_r );
74 /** Ctor \overload without optional title */
75 DrunkenBishop( const std::string & data_r, unsigned height_r )
76 : DrunkenBishop( data_r, std::string(), height_r )
79 /** Ctor also taking a desired board height and width (even values are incremented). */
80 DrunkenBishop( const std::string & data_r, const std::string & title_r, unsigned height_r, unsigned width_r );
81 /** Ctor \overload without optional title */
82 DrunkenBishop( const std::string & data_r, unsigned height_r, unsigned width_r )
83 : DrunkenBishop( data_r, std::string(), height_r, width_r )
90 /* Rendering options */
92 USE_COLOR = (1<<0), ///< use colors
94 ZYPP_DECLARE_FLAGS(Options,OptionBits);
96 /** Render board to steam.*/
97 std::ostream & dumpOn( std::ostream & str, Options options_r = Options() ) const
98 { return dumpOn( str, std::string(), options_r ); }
99 /** \overload taking an indent string prefixing each line. */
100 std::ostream & dumpOn( std::ostream & str, const std::string & prefix_r, Options options_r = Options() ) const;
102 /** Render board as string.*/
103 std::string asString( Options options_r = Options() ) const
104 { return asString( std::string(), options_r ); }
105 /** \overload taking an indent string prefixing each line. */
106 std::string asString( const std::string & prefix_r, Options options_r = Options() ) const;
108 /** Render to an array of lines. */
109 std::vector<std::string> asLines( Options options_r = Options() ) const
110 { return asLines( std::string(), options_r ); }
111 /** \overload taking an indent string prefixing each line. */
112 std::vector<std::string> asLines( const std::string & prefix_r, Options options_r = Options() ) const;
115 class Impl; ///< Implementation class.
117 RW_pointer<Impl> _pimpl; ///< Pointer to implementation.
120 ZYPP_DECLARE_OPERATORS_FOR_FLAGS(DrunkenBishop::Options);
122 /** \relates DrunkenBishop Stream output */
123 inline std::ostream & operator<<( std::ostream & str, const DrunkenBishop & obj )
124 { return obj.dumpOn( str ); }
127 ///////////////////////////////////////////////////////////////////
129 ///////////////////////////////////////////////////////////////////
130 #endif // ZYPP_BASE_DRUNKENBISHOP_H