func (c CipherInfo) Pretty() string { var colour func(string) string = nil suffix := "" if c.Kex.Broken || c.Auth.Broken || c.Cipher.Broken || c.MAC.Broken { colour = tc.Red suffix = " INSECURE" } else if c.Cipher.KeySize < 128 || c.MAC.TagSize < 160 { colour = tc.Yellow suffix = " WEAK" } pad := " " fs := tc.Yellow("no FS") if c.Kex.ForwardSecure { fs = tc.Green(" FS ") } aead := " " if c.MAC.AEAD { aead = "AEAD" } cstr := fmt.Sprintf("%3d", c.Cipher.KeySize) if colour == nil && c.Kex.ForwardSecure && c.Cipher.KeySize >= 128 && c.MAC.AEAD { colour = tc.Green } if colour == nil { colour = func(s string) string { return s } } return fmt.Sprintf("%s%s %s %s %s%s", colour(c.Name), pad[len(c.Name)%len(pad):], fs, colour(cstr), colour(aead), colour(suffix)) }
func main() { fmt.Printf("System colours:\n") fmt.Printf("%s %s\n", tc.Black("Black"), tc.Bblack("Bright Black")) fmt.Printf("%s %s\n", tc.Blue("Blue"), tc.Bblue("Bright Blue")) fmt.Printf("%s %s\n", tc.Green("Green"), tc.Bgreen("Bright Green")) fmt.Printf("%s %s\n", tc.Cyan("Cyan"), tc.Bcyan("Bright Cyan")) fmt.Printf("%s %s\n", tc.Red("Red"), tc.Bred("Bright Red")) fmt.Printf("%s %s\n", tc.Purple("Purple"), tc.Bpurple("Bright Purple")) fmt.Printf("%s %s\n", tc.Yellow("Yellow"), tc.Byellow("Bright Yellow")) fmt.Printf("%s %s\n", tc.White("White"), tc.Bwhite("Bright White")) fmt.Printf("\n 256ish colour cube\n") fmt.Print("4-bit palette: ") for i := 0; i < 16; i++ { fmt.Print(tc.Foreground8(tc.C256(i), "::")) } fmt.Print("\n ") for i := 0; i < 16; i++ { fmt.Print(tc.Background8(tc.C256(i), " ")) } fmt.Print("\n") for r0 := 0; r0 < 6; r0 += 3 { for g := 0; g < 6; g++ { for r := 0; r < 3; r++ { for b := 0; b < 6; b++ { c := tc.Colour256(r+r0, g, b) fmt.Print(tc.Foreground8(c, "::")) } fmt.Print(" ") } fmt.Print(" ") for r := 0; r < 3; r++ { for b := 0; b < 6; b++ { c := tc.Colour256(r+r0, g, b) fmt.Print(tc.Background8(c, " ")) } fmt.Print(" ") } fmt.Print("\n") } fmt.Print("\n") } fmt.Print("4.5-bit greyscale ramp: ") for i := 232; i < 256; i++ { fmt.Print(tc.Foreground8(tc.C256(i), "::")) } fmt.Print("\n ") for i := 232; i < 256; i++ { fmt.Print(tc.Background8(tc.C256(i), " ")) } fmt.Print("\n") }
func main() { reader, err := os.Open(*image_file) if err != nil { log.Fatal(err) } defer reader.Close() m, _, err := image.Decode(reader) if err != nil { log.Fatal(err) } bounds := m.Bounds() fmt.Printf("Image is %s by %s pixels wide\n", tc.Green(fmt.Sprintf("%d", bounds.Max.X)), tc.Green(fmt.Sprintf("%d", bounds.Max.Y))) if *use_24bit { Write24(m, bounds) } else { Write8(m, bounds) } }
func prettyCertificate(cert *x509.Certificate) (string, string) { key := "unknown" if cert.PublicKeyAlgorithm == x509.RSA { pk, ok := cert.PublicKey.(*rsa.PublicKey) if !ok { key = tc.Bred("RSA - error") } else { col := cStrength(pk.N.BitLen()) key = col(fmt.Sprintf("RSA-%d", pk.N.BitLen())) } } else if cert.PublicKeyAlgorithm == x509.DSA { pk, ok := cert.PublicKey.(*dsa.PublicKey) if !ok { key = tc.Bred("DSA - error") } else { bl := pk.P.BitLen() col := tc.Red if bl < 1536 { col = tc.Bred } key = col(fmt.Sprintf("DSA-%d", bl)) } } else if cert.PublicKeyAlgorithm == x509.ECDSA { pk, ok := cert.PublicKey.(*ecdsa.PublicKey) if !ok { key = tc.Bred("ECDSA - error") } else { bl := pk.Params().P.BitLen() col := tc.Green if bl < 224 { col = tc.Red } else if bl < 256 { col = tc.Yellow } key = col(fmt.Sprintf("ECDSA-%d", bl)) } } sig := strSigAlg(cert.SignatureAlgorithm) if cert.SignatureAlgorithm == x509.UnknownSignatureAlgorithm || cert.SignatureAlgorithm == x509.MD2WithRSA || cert.SignatureAlgorithm == x509.MD5WithRSA { sig = tc.Bred(sig) } else if cert.SignatureAlgorithm == x509.SHA1WithRSA || cert.SignatureAlgorithm == x509.DSAWithSHA1 || cert.SignatureAlgorithm == x509.DSAWithSHA256 || cert.SignatureAlgorithm == x509.ECDSAWithSHA1 { sig = tc.Red(sig) } else { sig = tc.Green(sig) } subject := cert.Subject.CommonName if len(subject) > 45 { subject = subject[0:45] } issuer := cert.Issuer.CommonName if len(issuer) > 45 { issuer = issuer[0:45] } fpr := tc.Bblack(fmt.Sprintf("%x", sha1.Sum(cert.Raw))) subject = fmt.Sprintf("subject: %-45s key type: %s / sig: %s", subject, key, sig) issuer = fmt.Sprintf("issuer: %-45s fingerprint: %s", issuer, fpr) return subject, issuer }