X-Git-Url: https://git.realraum.at/?p=svn42.git;a=blobdiff_plain;f=go%2Fdoor_nick_lookup_zmq%2Fkeys_file.go;fp=go%2Fdoor_nick_lookup_zmq%2Fkeys_file.go;h=0000000000000000000000000000000000000000;hp=4cdb29489046257900d0571ff80c41f46be05670;hb=c775b5528f8f96e75c28264b9cea8525c6da9298;hpb=a87c91b7d4544703879b7ef6e472b863765e3949 diff --git a/go/door_nick_lookup_zmq/keys_file.go b/go/door_nick_lookup_zmq/keys_file.go deleted file mode 100644 index 4cdb294..0000000 --- a/go/door_nick_lookup_zmq/keys_file.go +++ /dev/null @@ -1,54 +0,0 @@ -// (c) Bernhard Tittelbach, 2013 - -package main - -import ( - "log" - "regexp" - "strconv" - "errors" - "os" - "bufio" -) - -var re_keynickline *regexp.Regexp = regexp.MustCompile("^\\s*([0-9a-fA-F]+)\\s+((?:\\p{Latin}|\\d)+).*") - -type KeyNickStore map[uint64]string - -func (key_nick_map *KeyNickStore) LoadKeysFile(filename string) error { - keysfile, err := os.OpenFile(filename, os.O_RDONLY, 0400) // For read access. - defer keysfile.Close() - if err != nil { - return err - } - - //clear map - *key_nick_map = make(KeyNickStore) - - linescanner := bufio.NewScanner(keysfile) - linescanner.Split(bufio.ScanLines) - for linescanner.Scan() { - m := re_keynickline.FindStringSubmatch(linescanner.Text()) - if len(m) > 2 { - if kuint, err := strconv.ParseUint(m[1], 16, 64); err == nil { - (*key_nick_map)[kuint] = m[2] - } else { - log.Print("Error converting hex-cardid:",m[0]) - } - } - } - return nil -} - -func (key_nick_map *KeyNickStore) LookupHexKeyNick( key string ) (string, error) { - kuint, err := strconv.ParseUint(key, 16, 64) - if err != nil { - return "", errors.New("Invalid Hex-Card-Id") - } - nick, present := (*key_nick_map)[kuint] - if present { - return nick, nil - } else { - return "", errors.New("Key Unknown") - } -} \ No newline at end of file