github.com/la5nta/wl2k-go@v0.11.8/fbb/mid.go (about) 1 // Copyright 2015 Martin Hebnes Pedersen (LA5NTA). All rights reserved. 2 // Use of this source code is governed by the MIT-license that can be 3 // found in the LICENSE file. 4 5 package fbb 6 7 import ( 8 "crypto/md5" 9 "encoding/base32" 10 "fmt" 11 "time" 12 ) 13 14 const MaxMIDLength = 12 15 16 // Generates a unique message ID in the format specified by the protocol. 17 func GenerateMid(callsign string) string { 18 sum := md5.Sum(midPayload(callsign, time.Now())) 19 return base32.StdEncoding.EncodeToString(sum[0:])[0:MaxMIDLength] 20 } 21 22 func midPayload(callsign string, t time.Time) []byte { 23 return []byte(fmt.Sprintf("%s-%s", time.Now(), callsign)) 24 }