Documentation ¶
Overview ¶
Package geocrypt implements a geographic cryptographic hash.
Example (Kryptos) ¶
package main import ( "fmt" "log" "github.com/kortschak/geocrypt" ) func main() { lat := 38.9521808 lon := -77.1458137 text := "Kryptos" prec := 6 bits := geocrypt.Bits(prec) latErr, lonErr := geocrypt.Error(bits) fmt.Printf("prec=%d bits=%d error lat=%.2e lon=%.2e\n", prec, bits, latErr, lonErr) h, err := geocrypt.Hash(lat, lon, text, prec) if err != nil { log.Fatal(err) } // Compare against reduced accuracy location. // First without note text. fmt.Println(geocrypt.Compare(h, 38.95218, -77.14581, "")) // And then with note text. fmt.Println(geocrypt.Compare(h, 38.95218, -77.14581, text)) }
Output: prec=6 bits=48 error lat=1.07e-05 lon=2.15e-05 0 geocrypt: hashedLocation is not the hash of the given location 48 <nil>
Index ¶
- Constants
- Variables
- func Bits(prec int) int
- func Compare(hashedLocation []byte, lat, long float64, text string) (bits int, err error)
- func Error(bits int) (lat, long float64)
- func Geohash(lat, long float64, bits int) ([]byte, error)
- func Hash(lat, long float64, text string, precs ...int) ([]byte, error)
- func Location(geohash []byte) (lat, long float64, bits int, err error)
- func Prec(bits int) int
Examples ¶
Constants ¶
const ( // MinPrecision is the minimum allowable precision // that may be passed to Hash and Error. MinPrecision = 1 // MaxPrecision is the maximum allowable precision // that may be passed to Hash and Error. MaxPrecision = 9 // DefaultPrecision corresponds to approximately one // diagonal metre at the equator. DefaultPrecision = 7 )
Variables ¶
var ErrInvalidPrecision = errors.New("geocrypt: location precision out of range")
The error returned from Hash and Geohash when the precision is out of the valid range.
var ErrMismatchedHashAndLocation = errors.New("geocrypt: hashedLocation is not the hash of the given location")
The error returned from Compare when a location and hash do not match.
var ErrTextTooLong = errors.New("geocrypt: note text is too long")
The error returned from Hash or Compare when note text is longer than 64 bytes.
Functions ¶
func Compare ¶
Compare compares the geocrypt hashed location with the location at latitude and longitude and note text. The note text is appended the the geohash of the location before comparing to the hashed location. It returns the highest number of geohash precision bits in the hash set on success or an error on failure.
func Error ¶
Error returns the latitude and longitude error for the given bit precision. It will return NaN when bits is less than one or greater than 60.
func Geohash ¶
Geohash returns the geohash for the given latitude and longitude with the given bit precision. The value of bits must not be less than five or greater than 60.
func Hash ¶
Hash returns the geocrypt hash set of the location at the given latitude and longitude and note text with the given precisions. The note text is appended to the geohash of the location before hashing. If no precision is given, DefaultPrecision is used. When more than one precision is given, the hashes are concatenated in order of descending precision.
Types ¶
This section is empty.