// CreateContext creates a new SRTP Context.
//
// CreateContext receives variable number of ContextOption-s.
// Passing multiple options which set the same parameter let the last one valid.
// Following example create SRTP Context with replay protection with window size of 256.
//
//   decCtx, err := srtp.CreateContext(key, salt, profile, srtp.SRTPReplayProtection(256))
//
CreateContext creates a new SRTP Context.

CreateContext receives variable number of ContextOption-s.
Passing multiple options which set the same parameter let the last one valid.
Following example create SRTP Context with replay protection with window size of 256.

decCtx, err := srtp.CreateContext(key, salt, profile, srtp.SRTPReplayProtection(256))
// CreateContext creates a new SRTP Context . // // CreateContext receives variable number of ContextOption - s . // Passing multiple options which set the same parameter let the last one valid . // Following example create SRTP Context with replay protection with window size of 256 . // // decCtx err : = srtp . CreateContext ( key salt profile srtp . SRTPReplayProtection ( 256 )) //
func CreateContext(masterKey, masterSalt []byte, profile ProtectionProfile, opts ...ContextOption) (c *Context, err error) {
	keyLen, err := profile.keyLen()
	if err != nil {
		return nil, err
	}
	saltLen, err := profile.saltLen()
	if err != nil {
		return nil, err
	}
	if masterKeyLen := len(masterKey); masterKeyLen != keyLen {
		return c, fmt.Errorf("SRTP Master Key must be len %d, got %d", masterKey, keyLen)
	} else if masterSaltLen := len(masterSalt); masterSaltLen != saltLen {
		return c, fmt.Errorf("SRTP Salt must be len %d, got %d", saltLen, masterSaltLen)
	}
	c = &Context{
		srtpSSRCStates:  map[uint32]*srtpSSRCState{},
		srtcpSSRCStates: map[uint32]*srtcpSSRCState{},
	}
	switch profile {
	case ProtectionProfileAeadAes128Gcm:
		c.cipher, err = newSrtpCipherAeadAesGcm(masterKey, masterSalt)
	case ProtectionProfileAes128CmHmacSha1_80:
		c.cipher, err = newSrtpCipherAesCmHmacSha1(masterKey, masterSalt)
	default:
		return nil, fmt.Errorf("no such SRTP Profile %#v", profile)
	}
	if err != nil {
		return nil, err
	}
	for _, o := range append(
		[]ContextOption{ 
			SRTPNoReplayProtection(),
			SRTCPNoReplayProtection(),
		},
		opts..., 
	) {
		if errOpt := o(c); errOpt != nil {
			return nil, errOpt
		}
	}
	return c, nil
}
func CreateContext ( masterKey , masterSalt [ ] byte , profile ProtectionProfile , opts ... ContextOption ) ( c * Context , err error ) { keyLen , err := profile . keyLen ( ) if err != nil { return nil , err } saltLen , err := profile . saltLen ( ) if err != nil { return nil , err } if masterKeyLen := len ( masterKey ) ; masterKeyLen != keyLen { return c , fmt . Errorf ( " " , masterKey , keyLen ) } else if masterSaltLen := len ( masterSalt ) ; masterSaltLen != saltLen { return c , fmt . Errorf ( " " , saltLen , masterSaltLen ) } c = & Context { srtpSSRCStates : map [ uint32 ] * srtpSSRCState { } , srtcpSSRCStates : map [ uint32 ] * srtcpSSRCState { } , } switch profile { case ProtectionProfileAeadAes128Gcm : c . cipher , err = newSrtpCipherAeadAesGcm ( masterKey , masterSalt ) case ProtectionProfileAes128CmHmacSha1_80 : c . cipher , err = newSrtpCipherAesCmHmacSha1 ( masterKey , masterSalt ) default : return nil , fmt . Errorf ( " " , profile ) } if err != nil { return nil , err } for _ , o := range append ( [ ] ContextOption { SRTPNoReplayProtection ( ) , SRTCPNoReplayProtection ( ) , } , opts ... , ) { if errOpt := o ( c ) ; errOpt != nil { return nil , errOpt } } return c , nil }
CreateContext creates a new SRTP Context.
CreateContext creates a new SRTP Context .
// Default options // User specified options