Add Nonce spec.
This commit is contained in:
		
							parent
							
								
									b4fe9ef1c3
								
							
						
					
					
						commit
						c470ef8865
					
				
					 1 changed files with 31 additions and 0 deletions
				
			
		
							
								
								
									
										31
									
								
								spec/sodium/nonce_spec.cr
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								spec/sodium/nonce_spec.cr
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,31 @@ | ||||||
|  | require "../spec_helper" | ||||||
|  | require "../../src/sodium/nonce" | ||||||
|  | 
 | ||||||
|  | zero = Bytes.new(Sodium::Nonce::NONCE_SIZE) | ||||||
|  | one = Bytes.new(Sodium::Nonce::NONCE_SIZE).dup | ||||||
|  | one[0] = 1_u8 | ||||||
|  | 
 | ||||||
|  | describe Sodium::Nonce do | ||||||
|  |   it "generates a random nonce" do | ||||||
|  |     nonce = Sodium::Nonce.random | ||||||
|  |     nonce.should_not eq zero | ||||||
|  |   end | ||||||
|  | 
 | ||||||
|  |   it "loads an existing nonce" do | ||||||
|  |     nonce = Sodium::Nonce.new one | ||||||
|  |     nonce.to_slice.should eq one | ||||||
|  |   end | ||||||
|  | 
 | ||||||
|  |   it "zero nonce with increment" do | ||||||
|  |     nonce = Sodium::Nonce.zero | ||||||
|  |     nonce.to_slice.should eq zero | ||||||
|  | 
 | ||||||
|  |     nonce.used?.should be_false | ||||||
|  |     nonce.used! | ||||||
|  |     nonce.used?.should be_true | ||||||
|  | 
 | ||||||
|  |     nonce.increment | ||||||
|  |     nonce.to_slice.should eq one | ||||||
|  |     nonce.used?.should be_false | ||||||
|  |   end | ||||||
|  | end | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Didactic Drunk
						Didactic Drunk