HostAddress.go 1013 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package types
  2. // Reference: https://www.ietf.org/rfc/rfc4120.txt
  3. // Section: 5.2.5
  4. import (
  5. "github.com/jcmturner/asn1"
  6. )
  7. /*
  8. HostAddress and HostAddresses
  9. HostAddress ::= SEQUENCE {
  10. addr-type [0] Int32,
  11. address [1] OCTET STRING
  12. }
  13. -- NOTE: HostAddresses is always used as an OPTIONAL field and
  14. -- should not be empty.
  15. HostAddresses -- NOTE: subtly different from rfc1510,
  16. -- but has a value mapping and encodes the same
  17. ::= SEQUENCE OF HostAddress
  18. The host address encodings consist of two fields:
  19. addr-type
  20. This field specifies the type of address that follows. Pre-
  21. defined values for this field are specified in Section 7.5.3.
  22. address
  23. This field encodes a single address of type addr-type.
  24. */
  25. type HostAddresses []HostAddress
  26. type HostAddress struct {
  27. AddrType int `asn1:"explicit,tag:0"`
  28. Address []byte `asn1:"explicit,tag:1"`
  29. }
  30. func (h *HostAddress) GetAddress() (string, error) {
  31. var b []byte
  32. _, err := asn1.Unmarshal(h.Address, &b)
  33. return string(b), err
  34. }