package org.bouncycastle.crypto.tls;

import java.io.IOException;

public class ProtocolVersion
{
    public static final ProtocolVersion SSLv3 = new ProtocolVersion(0x0300);
    public static final ProtocolVersion TLSv10 = new ProtocolVersion(0x0301);
    public static final ProtocolVersion TLSv11 = new ProtocolVersion(0x0302);
    public static final ProtocolVersion TLSv12 = new ProtocolVersion(0x0303);
    public static final ProtocolVersion DTLSv10 = new ProtocolVersion(0xFEFF);
    public static final ProtocolVersion DTLSv12 = new ProtocolVersion(0xFEFD);

    private int version;

    private ProtocolVersion(int v)
    {
        version = v & 0xffff;
    }

    public int getFullVersion()
    {
        return version;
    }

    public int getMajorVersion()
    {
        return version >> 8;
    }

    public int getMinorVersion()
    {
        return version & 0xff;
    }

    public boolean isDTLS()
    {
	return getMajorVersion() == 0xFE;
    }

    public boolean isSSL()
    {
	return this == SSLv3;
    }

    public boolean isTLS()
    {
	return getMajorVersion() == 0x03 && !isSSL();
    }

    public boolean equals(Object obj)
    {
        return this == obj;
    }

    public int hashCode()
    {
        return version;
    }

    public static ProtocolVersion get(int major, int minor) throws IOException
    {
        switch (major)
        {
            case 0x03:
                switch (minor)
                {
                    case 0x00:
                        return SSLv3;
                    case 0x01:
                        return TLSv10;
                    case 0x02:
                        return TLSv11;
                    case 0x03:
                        return TLSv12;
                }
            case 0xFE:
                switch (minor)
                {
                    case 0xFF:
                        return DTLSv10;
                    case 0xFD:
                        return DTLSv12;
                }
        }

        throw new TlsFatalAlert(AlertDescription.illegal_parameter);
    }
}

@@ -92,10 +92,11 @@
 sion
+ %7B
 %0A
-%7B
 %0A   
@@ -622,20 +622,16 @@
 n(int v)
-%0A   
  %7B%0A     
@@ -685,36 +685,32 @@
 getFullVersion()
-%0A   
  %7B%0A        retur
@@ -751,36 +751,32 @@
 etMajorVersion()
-%0A   
  %7B%0A        retur
@@ -830,20 +830,16 @@
 ersion()
-%0A   
  %7B%0A     
@@ -894,32 +894,35 @@
 ean isDTLS()
-%0A
+ %7B%0A   
     
-%7B%0A%09
+ 
 return getMa
@@ -976,24 +976,27 @@
  isSSL()
+ %7B
 %0A    
-%7B%0A%09
+    
 return t
@@ -1046,16 +1046,19 @@
 LS()
-%0A
+ %7B%0A  
     
-%7B%0A%09
+  
 retu
@@ -1129,13 +1129,658 @@
 ean 
-e
+isE
 qual
+OrEarlierVersionOf(ProtocolVersion version) %7B%0A        if (getMajorVersion() != version.getMajorVersion()) %7B%0A            return false;%0A        %7D%0A        int diffMinorVersion = version.getMinorVersion() - getMinorVersion();%0A        return isDTLS() ? diffMinorVersion %3C= 0 : diffMinorVersion %3E= 0;%0A    %7D%0A%0A    public boolean isLaterVersionOf(ProtocolVersion version) %7B%0A        if (getMajorVersion() != version.getMajorVersion()) %7B%0A            return false;%0A        %7D%0A        int diffMinorVersion = version.getMinorVersion() - getMinorVersion();%0A        return isDTLS() ? diffMinorVersion %3E 0 : diffMinorVersion %3C 0;%0A    %7D%0A%0A    public boolean equal
 s(Ob
@@ -1788,20 +1788,16 @@
 ect obj)
-%0A   
  %7B%0A     
@@ -1851,20 +1851,16 @@
 shCode()
-%0A   
  %7B%0A     
@@ -1963,20 +1963,16 @@
 xception
-%0A   
  %7B%0A     
@@ -1992,23 +1992,11 @@
 jor)
-%0A        %7B%0A    
+ %7B%0A
     
@@ -2014,36 +2014,32 @@
 03:%0A            
- 
-   
 switch (minor)%0A 
@@ -2040,35 +2040,11 @@
 nor)
-%0A                %7B%0A        
+ %7B%0A
     
@@ -2074,32 +2074,24 @@
             
-        
 return SSLv3
@@ -2100,32 +2100,24 @@
             
-     
-   
 case 0x01:%0A 
@@ -2115,24 +2115,16 @@
 e 0x01:%0A
-        
         
@@ -2154,32 +2154,24 @@
             
-   
-     
 case 0x02:%0A 
@@ -2169,24 +2169,16 @@
 e 0x02:%0A
-        
         
@@ -2208,32 +2208,24 @@
             
-        
 case 0x03:%0A 
@@ -2235,32 +2235,24 @@
             
-      
-  
 return TLSv1
@@ -2258,36 +2258,32 @@
 12;%0A            
-    
 %7D%0A            ca
@@ -2268,36 +2268,32 @@
       %7D%0A        
- 
-   
 case 0xFE:%0A     
@@ -2291,36 +2291,32 @@
 FE:%0A            
-   
- 
 switch (minor)%0A 
@@ -2317,35 +2317,11 @@
 nor)
-%0A                %7B%0A        
+ %7B%0A
     
@@ -2351,32 +2351,24 @@
             
-  
-      
 return DTLSv
@@ -2379,32 +2379,24 @@
             
-       
- 
 case 0xFD:%0A 
@@ -2394,24 +2394,16 @@
 e 0xFD:%0A
-        
         
@@ -2418,36 +2418,32 @@
 return DTLSv12;%0A
-    
             %7D%0A  

Add methods for comparing versions