kunt

golang IRC bot
git clone git://git.2f30.org/kunt
Log | Files | Refs | LICENSE

utils.go (730B)


      1 // Copyright 2013 TLH and dsp. All rights reserved.
      2 // Use of this source code is governed by a BSD-style
      3 // license that can be found in the LICENSE file.
      4 
      5 package irc
      6 
      7 import (
      8 	"crypto/tls"
      9 	"unicode"
     10 )
     11 
     12 func loadCerts() (*tls.Config, error) {
     13 	cert, err := tls.LoadX509KeyPair("certs/client.pem",
     14 		"certs/client.key")
     15 	if err != nil {
     16 		return nil, err
     17 	}
     18 	return &tls.Config{
     19 		Certificates:       []tls.Certificate{cert},
     20 		InsecureSkipVerify: true,
     21 	}, nil
     22 }
     23 
     24 func validNick(n string) bool {
     25 	for i, _ := range n {
     26 		c := n[i]
     27 		if !unicode.IsLetter(rune(c)) &&
     28 			!unicode.IsDigit(rune(c)) {
     29 			switch c {
     30 			case '[', ']', '\\', '`', '_', '^', '{', '|', '}', '-':
     31 			default:
     32 				return false
     33 			}
     34 		}
     35 	}
     36 	return true
     37 }