github.com/cyverse/go-irodsclient@v0.13.2/irods/types/ssl_config.go (about)

     1  package types
     2  
     3  import (
     4  	"os"
     5  
     6  	"golang.org/x/xerrors"
     7  )
     8  
     9  // IRODSSSLConfig contains irods ssl configuration
    10  type IRODSSSLConfig struct {
    11  	CACertificateFile   string
    12  	EncryptionKeySize   int
    13  	EncryptionAlgorithm string
    14  	SaltSize            int
    15  	HashRounds          int
    16  }
    17  
    18  // CreateIRODSSSLConfig creates IRODSSSLConfig
    19  func CreateIRODSSSLConfig(caCertFile string, keySize int, algorithm string, saltSize int,
    20  	hashRounds int) (*IRODSSSLConfig, error) {
    21  	return &IRODSSSLConfig{
    22  		CACertificateFile:   caCertFile,
    23  		EncryptionKeySize:   keySize,
    24  		EncryptionAlgorithm: algorithm,
    25  		SaltSize:            saltSize,
    26  		HashRounds:          hashRounds,
    27  	}, nil
    28  }
    29  
    30  // ReadCACert returns CA Cert data
    31  func (config *IRODSSSLConfig) ReadCACert() ([]byte, error) {
    32  	if len(config.CACertificateFile) > 0 {
    33  		caCert, err := os.ReadFile(config.CACertificateFile)
    34  		if err != nil {
    35  			return nil, xerrors.Errorf("failed to read from file %s: %w", config.CACertificateFile, err)
    36  		}
    37  		return caCert, nil
    38  	}
    39  
    40  	return nil, xerrors.Errorf("ca certificate file is not set")
    41  }