File: decode.go

package info (click to toggle)
golang-github-go-crypt-crypt 0.4.7-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 516 kB
  • sloc: makefile: 4
file content (32 lines) | stat: -rw-r--r-- 981 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package crypt

import (
	"github.com/go-crypt/crypt/algorithm"
)

// The global Decoder. This is utilized by the Decode function.
var gdecoder *Decoder

// Decode is a convenience function which wraps the Decoder functionality. It's recommended to create your own decoder
// instead via NewDecoder or NewDefaultDecoder.
//
// CRITICAL STABILITY NOTE: the decoders loaded via this function are not guaranteed to remain the same. It is strongly
// recommended that users implementing this library use the NewDecoder function and explicitly register each decoder
// which they wish to support.
func Decode(encodedDigest string) (digest algorithm.Digest, err error) {
	if digest, err = decode(encodedDigest); err != nil {
		return nil, err
	}

	return digest, nil
}

func decode(encodedDigest string) (digest algorithm.Digest, err error) {
	if gdecoder == nil {
		if gdecoder, err = NewDefaultDecoder(); err != nil {
			return nil, err
		}
	}

	return gdecoder.Decode(encodedDigest)
}