Exemplo n.º 1
0
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))
}
Exemplo n.º 2
0
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")
}