File: mid.go

package info (click to toggle)
golang-github-la5nta-wl2k-go 0.11.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,856 kB
  • sloc: ansic: 14; makefile: 2
file content (24 lines) | stat: -rw-r--r-- 624 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Copyright 2015 Martin Hebnes Pedersen (LA5NTA). All rights reserved.
// Use of this source code is governed by the MIT-license that can be
// found in the LICENSE file.

package fbb

import (
	"crypto/md5"
	"encoding/base32"
	"fmt"
	"time"
)

const MaxMIDLength = 12

// Generates a unique message ID in the format specified by the protocol.
func GenerateMid(callsign string) string {
	sum := md5.Sum(midPayload(callsign, time.Now()))
	return base32.StdEncoding.EncodeToString(sum[0:])[0:MaxMIDLength]
}

func midPayload(callsign string, t time.Time) []byte {
	return []byte(fmt.Sprintf("%s-%s", time.Now(), callsign))
}