util

package
v0.0.0-...-0aeaaa6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2025 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AddressLength = 20 // bytes
)

Variables

This section is empty.

Functions

func CborDecode

func CborDecode(payload []byte, output interface{}) error

Decode cbor message

func CborEncode

func CborEncode(payload interface{}) ([]byte, error)

Encode message in Cbor format

func CheckMXRecords

func CheckMXRecords(domain string) (bool, error)

func ConvertFromSmtpEmail

func ConvertFromSmtpEmail(email *abi.Mail) (*types.SmtpEmailInput, error)

ConvertFromSmtpEmail converts the input email to the required format for the SMTP Mailio interface. It takes an email as a parameter and returns the converted email format or an error.

func ConvertToSmtpEmail

func ConvertToSmtpEmail(email types.SmtpEmailInput) (*abi.Mail, error)

ConvertSMTP converts the input email to the required format for the SMTP Mailio interface. It takes an email as a parameter and returns the converted email format or an error.

param email - the email input to be converted return - converted email format or an error if conversion fails Errors: - "invalid email address" if the FROM email address is invalid (ErrInvalidFormat) - "no address" if any invalid addressess are provided for recipients (to, cc, bcc) (ErrInvalidRecipient)

func CreateMailioDIDDocument

func CreateMailioDIDDocument() (*mailiodid.Document, error)

TODO! rename the CreateMailioDIDDocument (although it's functionality is ok, but the name is a bit misleading) CreateMailioDIDDocument creates a new mailio DID document (server DID)

func DIDDocumentToUniqueID

func DIDDocumentToUniqueID(message *types.DIDCommMessage, optionalSuffix string) (string, error)

converts the DID document to unique ID

func DeepCopy

func DeepCopy(src, dest interface{}) error

func DetectInlineContentType

func DetectInlineContentType(filename string) bool

DetectInlineContentType checks if the file extension is for inline content

func ExtractDIDMessageEndpoint

func ExtractDIDMessageEndpoint(didDoc *did.Document) string

Extracts the message endpoint from DID document in case localhost/127.0.0.1 schema is http, otherwise default schema is https

func ExtractRootDomain

func ExtractRootDomain(domain string) (string, error)

func ExtractSmtpSendingDomain

func ExtractSmtpSendingDomain(domain string) (string, error)

Extract the corresponding smtp sending domain for the given domain from the configuration

func FixAndDecodeURLBase64

func FixAndDecodeURLBase64(base64String string) ([]byte, error)

func GenerateEd25519KeyPair

func GenerateEd25519KeyPair() (*string, *string, error)

Generated ed25519 signing key pair and returns base64 public key, private key returns publicKey, privateKey, error

func GenerateNonce

func GenerateNonce(n int) string

Generates a random nonce of custom length in bytes method based on https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-go

func GenerateTXTRecord

func GenerateTXTRecord(domain string, publicKeyBase64 string) (*string, error)

func GetDiskUsageFromDiskHandlers

func GetDiskUsageFromDiskHandlers(address string) int64

*

  • GetDiskUsageFromDiskHandlers returns the total disk usage for the given address from all disk usage handlers
  • @param address the address to get the disk usage for *

func GetTimestamp

func GetTimestamp() int64

func HexEncodeToString

func HexEncodeToString(str string) string

Encodes a string to hex

func IsEd25519PublicKey

func IsEd25519PublicKey(b64Key string) bool

Check if a base64 string is an ed25519 public key.

func IsNilOrEmpty

func IsNilOrEmpty(s *string) bool

func IsNumber

func IsNumber(s string) bool

IsNumber checks if a given string represents a valid number (integer or float)

func IsSupportedSmtpDomain

func IsSupportedSmtpDomain(domain string) bool

IsSupportedDomain checks if the domain is in the list of smtp server domains or mailio domains

func IsValidMailioAddress

func IsValidMailioAddress(address string) bool

helper to check if the mailio address is valid

func ListSmtpDomains

func ListSmtpDomains() []string

func MailioDNSDiscover

func MailioDNSDiscover(ctx context.Context, domain string) (*types.Discovery, error)

DNS discovery of the domain. Returns Discovery object with the following fields: - Domain: domain name - IsMailio: true if the domain supports Mailio exchange protocol - PublicKeyType: type of the public key (currently only ed25519 is supported) - PublicKey: base64 encoded public key - Ips: IP addresses of the domain

func MailioDNSParseTxtV1

func MailioDNSParseTxtV1(txt string) (*types.Discovery, error)

helper parsing function for MAILIO1 (version 1)

func ParseImageBytesToJPG

func ParseImageBytesToJPG(content []byte, mimeType string) (image.Image, error)
ParseImageBytes parses the image bytes and returns the image.Image object

Supported mime types are "image/jpg", "image/jpeg", "image/png"

  • @param content []byte
  • @param mimeType string
  • @return image.Image
  • @return error

func PublicKeyToMailioAddress

func PublicKeyToMailioAddress(pubKeyRaw []byte) (string, error)

func RawPublicKeyToMailioAddress

func RawPublicKeyToMailioAddress(pubKey ed25519.PublicKey) (string, error)

func ScrpyBase64ToMappingId

func ScrpyBase64ToMappingId(base64ScryptEmail string) (string, error)

Converting Scrypted base64 encoded email to mailio_mapping id

func ScryptEmail

func ScryptEmail(email string) (string, error)

func ServerSideHandshake

func ServerSideHandshake(publicServerKey ed25519.PublicKey, privateServerKey ed25519.PrivateKey, domain string) (*types.Handshake, error)

Handshake from the server side (this is usually used when user has no handshake for specific sender)

func Sha256Hex

func Sha256Hex(data []byte) string

Sha256Hex returns the sha256 hash of the data as a hex string

func Sign

func Sign(message []byte, privateKey ed25519.PrivateKey) ([]byte, error)

Signing message using ed25519

func SmtpMailToUniqueID

func SmtpMailToUniqueID(email *types.SmtpEmailInput, optionalSuffix string) (string, error)

func StringToInt

func StringToInt(str string) int

Decodes a hex string to a string

func StripDownToRawEmailOrMailioAddress

func StripDownToRawEmailOrMailioAddress(address string) (string, error)

helper to strip down the email address to raw email or mailio address

func SumUpItemsFromFolderCountResponse

func SumUpItemsFromFolderCountResponse(folders []string, response *types.CouchDBCountDistinctFromResponse) int

count the number of messages in all folders except sent

func ValidationErrorToMessage

func ValidationErrorToMessage(err error) string

ValidationErrorToMessage converts a validator.ValidationErrors to a string

func Verify

func Verify(message []byte, signature []byte, publicKeyBase64 string) (bool, error)

Verify message signature using ed25519

func VerifyHandshake

func VerifyHandshake(handshake *types.Handshake, userPublicKeyEd25519Base64 string) (bool, error)

VerifyHandshake verifies the signature of the handshake along with the basic sanity checks

Types

type Data

type Data struct {
	Value []types.KeyValue
}

type MailioAddress

type MailioAddress [AddressLength]byte

MailioAddress represents the 20 byte address (same as Ethereum account).

func BytesToAddress

func BytesToAddress(b []byte) MailioAddress

BytesToAddress returns Address with value b. If b is larger than len(h), b will be cropped from the left.

func (*MailioAddress) SetBytes

func (a *MailioAddress) SetBytes(b []byte)

SetBytes sets the address to the value of b. If b is larger than len(a), b will be cropped from the left.

type SafeFile

type SafeFile struct {
	// contains filtered or unexported fields
}

I/O thread-safe file operations

func NewSafeFile

func NewSafeFile(filename string) (*SafeFile, error)

func (*SafeFile) Close

func (sf *SafeFile) Close() error

func (*SafeFile) Read

func (sf *SafeFile) Read() (*Data, error)

func (*SafeFile) Write

func (sf *SafeFile) Write(data *Data) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL